Skip to content

MyPy typechecking method names that clash with other types #4577

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

Closed
alanhdu opened this issue Feb 15, 2018 · 1 comment
Closed

MyPy typechecking method names that clash with other types #4577

alanhdu opened this issue Feb 15, 2018 · 1 comment

Comments

@alanhdu
Copy link
Contributor

alanhdu commented Feb 15, 2018

Using mypy 0.560 (and with the current master) and python 3.6.4, typechecking the following function:

class A:
    def int(self) -> int:
        return 5

fails with:

test.py:2: error: Invalid type "test.A.int"

In general, it looks like if I define a method with the name of a type, I can no longer use that type in return annotations in that class.

@ilevkivskyi
Copy link
Member

I think this is a duplicate of #3775

The workaround is to use import builtins and then builtins.int.

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

2 participants