-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
"class property" should be Generic[T] #4731
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
Comments
This makes sense to me. It might even make sense to use two type variables for setting and getting. On the other hand, I don't know what the impact on type checkers is, since I think they usually hard-code properties. |
I was going to open a new issue in response to python/typing#758, but found this one already opened :) |
I seriously doubt this is idea is supported, but I'll ask anyway.... Is it possible to @overload
class property(Generic[_T]):
fget: Optional[Callable[[Any], _T]]
fset: Optional[Callable[[Any, _T], None]]
fdel: Optional[Callable[[Any], None]]
.... # The remaining signatures
@overload
class property(Generic[_T_contra, _T_co]):
fget: Optional[Callable[[Any], _T_co]]
fset: Optional[Callable[[Any, _T_contra], None]]
fdel: Optional[Callable[[Any], None]]
.... # The remaining signatures |
You can overloads its |
Though I guess that wouldn't give you a way to vary the number of type parameters. |
How about something like this?
Since the undefined type vars default to I'm happy to create a pull request if this is something that would potentially be accepted. What do you guys think? Edit: After writing this, I realized that @erictraut has written something similar |
Currently
property.__get__
returnsAny
, which loose information:typeshed/stdlib/3/builtins.pyi
Line 877 in c58a93b
This would be more correct for
property.__get__
to be generic and returnT
. Similar to cached_property:typeshed/stdlib/3/functools.pyi
Line 113 in 1dd1b70
The text was updated successfully, but these errors were encountered: