Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Function is missing type annotation for __init__(self) #5943

Closed
alex65536 opened this issue Nov 23, 2018 · 3 comments
Closed

Function is missing type annotation for __init__(self) #5943

alex65536 opened this issue Nov 23, 2018 · 3 comments

Comments

@alex65536
Copy link

alex65536 commented Nov 23, 2018

The minimal code is:

class MyClass:
    def __init__(self):
        pass

When running mypy code.cpp with the following mypy.ini

[mypy]
ignore_missing_imports = True
disallow_untyped_defs = True

it says:

code.py:2: error: Function is missing a type annotation

The expected result is not errors

@JelleZijlstra
Copy link
Member

That's because you have the disallow_untyped_defs flag on, which produces an error for function definitions without a type annotation. You should add -> None to the annotation for your method, or not use disallow_untyped_defs.

(Also, I'm happy to see that we're using mypy to check C++ code now. :) )

@andreymal
Copy link

@JelleZijlstra but -> None is implied (#604), so def __init__(self) actually has a type annotation, so this is a mypy bug?

@JelleZijlstra
Copy link
Member

We decided at the time to still require-> None for initializers with no arguments, so that the default would still be to leave these functions unchecked.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants