-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Add __new__ to tuple stub #2092
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
Conversation
stdlib/3/builtins.pyi
Outdated
| def indices(self, len: int) -> Tuple[int, int, int]: ... | ||
|
|
||
| class tuple(Sequence[_T_co], Generic[_T_co]): | ||
| def __new__(cls: Type[_T], iterable: Iterable[Any]=tuple()) -> _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 default should always be .... You should basically match __init__ here: take Iterable[_T_co] and return _T[_T_co].
stdlib/3/builtins.pyi
Outdated
| def indices(self, len: int) -> Tuple[int, int, int]: ... | ||
|
|
||
| class tuple(Sequence[_T_co], Generic[_T_co]): | ||
| def __new__(cls: Type[_T], iterable: Iterable[_T_co] = ...) -> _T[_T_co]: ... |
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.
It looks like _T[_T_co] is illegal, although conceptually it's what we want here. We could just return tuple[_T_co, ...], but that would not play well with subclasses.
@ilevkivskyi any ideas on how to spell this type?
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.
I think mypy ignores the return type of __new__ anyway. But IMO the type should be just (cls: Type[T], iterable: Iterable[_T_co] = ...) -> T
Closes: python#2091 Apply suggestions from python#2092
Closes: python#2091 Apply suggestions from python#2092
this solves python#2091 when checking Python 2 code (python#2092 only fixed it for Python 3).
Closes: #2091