Skip to content

Running mypy --strict, the variable without a type hint doesn't get error, not strictly checking the code #20255

@hyperkai

Description

@hyperkai

*Memo:

  • mypy --strict test.py
  • mypy 1.18.2
  • Python 3.14.0
  • Windows 11

Running mypy --strict, the function without type hints gets the errors, strictly checking the code as shown below:

def func(x):
    return x
# error: Function is missing a type annotation
def func(x) -> str:
    return x
# error: Function is missing a type annotation for one or more arguments
def func(x: str):
    return x
# error: Function is missing a return type annotation

But, running mypy --strict, the variable without a type hint doesn't get error, not strictly checking the code as shown below:

v = 'Hello'
# No error

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrong

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions