-
Notifications
You must be signed in to change notification settings - Fork 13
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
type checking for attributes #20
Comments
@glyph, yes, that README sentence refers to this issue. This feature was supported in the earlier version, but since interface checking was reimplemented, I had to drop it. The reason is documentde in mypy-zope/src/mypy_zope/plugin.py Lines 553 to 559 in ae7ed4b
|
If I remember correctly, the issue is boils down to the type difference between class and instance attributes, e.g. class Descriptor:
__get__(self, obj) -> int:
return 0
class IWhatever(Interface):
stuff: int = Attribute("name")
@implementer(IWhatever)
class Whatever:
stuff = Descriptor() The type of |
@kedder Thanks for the explanation. I went looking for how this was handled by from typing import Protocol
class Descriptor:
def __get__(self, obj: object) -> int:
return 0
def __set__(self, obj: object, value: int) -> None:
return None
def __delete__(self, obj: object) -> None:
return None
class Whatever:
stuff = Descriptor()
class WhateverProto(Protocol):
stuff: int
whatever: WhateverProto = Whatever() |
Looks like it's a known issue: python/mypy#5481 |
Would it be possible to make this a configuration option? There are some hacks which would make this possible (like what |
We can definiely make it an option. @glyph, can you try uncommenting these lines and check if that actually works for your project? mypy-zope/src/mypy_zope/plugin.py Lines 561 to 567 in ae7ed4b
|
Gotcha. There may be … significant latency on this experiment, since we're burning down LOTS of unrelated mypy errors on Twisted right now, so seeing how this works in practice might take a while. But @adiroiban @rodrigc might be interested to know that this is possible. |
This example doesn't complain:
even though the type of
stuff
doesn't match.This closed PR, from 2017, suggests that this syntax was intended to work one day:
zopefoundation/zope.interface#98
I'm guessing this is what the README is already talking about, when it says "Interface compatibility checker will not type-check non-method attributes"?
The text was updated successfully, but these errors were encountered: