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
bytes
should implement __new__
#2630
Comments
Could you give an example where this is a problem? |
They do, but the argument list is wrong. As a strawman example: class SHA1Hash(bytes):
def __new__(cls, b: bytes) -> 'SHA1Hash':
if len(b) != 20:
raise ValueError("Invalid SHA1Hash value!")
return super().__new__(cls, b) This doesn't typecheck, because the call to This is also a bit like the tuple case again in that |
Thanks for the explanation. Makes sense. We appreciate pull requests! |
|
Figure I should add a ref to the reason it was backed out: #1464 It appears it was backed out because the addition of Perhaps there needs to be a special case for these builtins to make constructing them work correctly? |
Closed by #4555 (and thank you for git-revise!) |
This seems like a similar issue to #2091. The
bytes
type implements__init__
but doesn't appear to provide an overload for__new__
. This makes it harder for subclasses ofbytes
to define their own behaviour for__new__
.typeshed/stdlib/3/builtins.pyi
Lines 344 to 355 in 9c3978e
This also appears to be the case for some of the other builtins (e.g.
str
)typeshed/stdlib/3/builtins.pyi
Lines 267 to 272 in 9c3978e
The text was updated successfully, but these errors were encountered: