Skip to content

Allow nested tuples in isinstance/issubclass #998

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

Merged
merged 1 commit into from
Mar 14, 2017

Conversation

pkch
Copy link
Contributor

@pkch pkch commented Mar 14, 2017

Fixes #997

@@ -718,8 +718,8 @@ def intern(string: str) -> str: ...
def iter(iterable: Iterable[_T]) -> Iterator[_T]: ...
@overload
def iter(function: Callable[[], _T], sentinel: _T) -> Iterator[_T]: ...
def isinstance(o: object, t: Union[type, Tuple[type, ...]]) -> bool: ...
def issubclass(cls: type, classinfo: Union[type, Tuple[type, ...]]) -> bool: ...
def isinstance(o: object, t: Union[type, Tuple[Union[type, Tuple], ...]]) -> bool: ...
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pkch @gvanrossum
I think here and below it should be Tuple[type, ...] no just Tuple at the end.
Otherwise isinstance(obj, ((1, 2), (3, 4)))will be valid.

This also applies to Python 3 stub.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem is that the tuple can be arbitrarily nested. Excluding that example would also exclude isinstance(x, (((int, int), int), int)).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I still prefer the restrictive version a bit more, but this is not important. Anyway, there is no perfect solution until we support recursive types. (Btw, they are in my plans right after Protocols).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants