-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Methods with the same name as a type sometimes cause error "not valid as a type" #15047
Comments
This example seems somewhat similar, i.e., class Foo:
@property
def type(self) -> str:
return "foo" is valid, however, class Foo:
@property
def type(self) -> str:
return "foo"
@property
def foo(self) -> type:
return Foo the inclusion of the
|
In your case, mypy's behaviour matches that of Python's scoping, no?
OP's case is definitely buggy, because no matter what mypy's behaviour is it should be robust to the presence of comments and whitespace |
Thanks @hauntsaninja for the response. What's your recommendation for a preferred solution? Is it simply to refer to the built-in, i.e.,
|
Using |
Bug Report
When using a decorator on a class method with the same name as a type used in its return type, and the method is decorated with a decorator that spans multiple lines, an error is thrown.
What puzzles me is that this only causes an error if the decorator spans multiple lines, not if it is just on a single line.
Neither pylint nur flake8 do complain about having a method that shadows another name in general. So I am assuming that this should be generally ok.
To Reproduce
Some more examples show that this
@property
) and custom defined decorators.Expected Behavior
Use the types from the outer scope to construct the return type and validate correctly.
Actual Behavior
Your Environment
mypy.ini
(and other config files): noneThe text was updated successfully, but these errors were encountered: