-
-
Notifications
You must be signed in to change notification settings - Fork 1.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
dataclasses: various fixes #4937
Conversation
stdlib/3.7/dataclasses.pyi
Outdated
def dataclass(__cls: Type[_T]) -> Type[_T]: ... | ||
@overload | ||
def dataclass(_cls: None) -> Callable[[Type[_T]], Type[_T]]: ... | ||
def dataclass(__cls: None) -> Callable[[Type[_T]], Type[_T]]: ... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The stubtest complaints are valid. The following is horrible, but possible:
from dataclasses import dataclass
class Foo:
x: int
y: str
dataclass(_cls=Foo)
print(Foo(42, ""))
@@ -76,6 +98,8 @@ def is_dataclass(obj: Any) -> bool: ... | |||
class FrozenInstanceError(AttributeError): ... | |||
|
|||
class InitVar(Generic[_T]): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this Generic? Should type
be of type Type[_T]
?
|
||
if sys.version_info >= (3, 8): | ||
@overload | ||
def dataclass(__cls: Type[_T]) -> Type[_T]: ... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Took me a long time to figure out that the difference between the branches is __cls
vs. _cls
. Maybe it's worth a comment.
Thanks, addressed (also fixed up |
__class_getitem__ and __init_subclass__ are always classmethods, even if they aren't decorated. We previously only handled this correctly if these methods weren't overloaded. This came up in python/typeshed#4937
…hod (#9921) __class_getitem__ and __init_subclass__ are always classmethods, even if they aren't decorated. We previously only handled this correctly if these methods weren't overloaded. This came up in python/typeshed#4937 Co-authored-by: hauntsaninja <>
No description provided.