decouple types.DynamicClassAttribute from property#13276
decouple types.DynamicClassAttribute from property#13276srittau merged 6 commits intopython:mainfrom
Conversation
This comment has been minimized.
This comment has been minimized.
stdlib/types.pyi
Outdated
| def __set__(self, instance: Any, value: Any) -> None: ... | ||
| def __delete__(self, instance: Any) -> None: ... | ||
| def getter(self, fget: Callable[[Any], Any]) -> DynamicClassAttribute: ... | ||
| def setter(self, fset: Callable[[Any, Any], None]) -> DynamicClassAttribute: ... |
There was a problem hiding this comment.
I think we want the special semantics where you can write @foo.setter later without type checkers complaining about a duplicate definition. That may be hard to achieve without aliasing property.
There was a problem hiding this comment.
Good point. I'll put together a test to find out.
There was a problem hiding this comment.
It seems that it works as expected in mypy but not pyright.
This comment has been minimized.
This comment has been minimized.
|
I opened a pyright issue for the test failure here. |
|
Pyright doesn't plan to support this, so there's nothing else to do here. |
|
After looking into it a little more, it seems like we can avoid regressions in pyright by pretending that DynamicClassAttribute inherits from property. That seems less wrong than pretending that it's just an alias for property. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
srittau
left a comment
There was a problem hiding this comment.
Thanks, just a nit about the unused return types of callables.
|
As-is, the callable return types match the definition of |
We should probably do that, but considering how fundamental that is, we should do it in a separate PR. |
Co-authored-by: Sebastian Rittau <[email protected]>
these can go away if we update property itself
|
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉 |
In addition to the cleared allowlist entries, this improves the inheritance of
enum.property.Previous: #12762
This is now enabled by mypy 1.14 and python/mypy#18150.