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

__set_name__ isn't checked #8057

Open
natedogith1 opened this issue Dec 3, 2019 · 1 comment
Open

__set_name__ isn't checked #8057

natedogith1 opened this issue Dec 3, 2019 · 1 comment
Labels
feature priority-1-normal topic-descriptors Properties, class vs. instance attributes

Comments

@natedogith1
Copy link

from typing import Type

class Foo:
	def __set_name__(self, owner: Type['Bar'], name: str) -> None:
		...

class Bar:
	foo_bar = Foo() # correctly passes

class Baz:
	foo_baz = Foo() # should fail

mypy correctly accepts Bar.foo_var, but incorrectly accepts Baz.foo_baz

@ethanhs ethanhs added bug mypy got something wrong priority-1-normal labels Dec 3, 2019
@ethanhs
Copy link
Collaborator

ethanhs commented Dec 3, 2019

I believe mypy isn't aware of __set_name__, this should be implemented.

I believe the generic definition of this is:

def __set_name__(self, owner: Type[Any], name: str) -> None: ...

We perhaps might be able to specialize based on the type of owner.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature priority-1-normal topic-descriptors Properties, class vs. instance attributes
Projects
None yet
Development

No branches or pull requests

3 participants