Skip to content
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

_ExcInfo and _OptExcInfo broken with new typeshed definition #1622

Closed
jakebailey opened this issue Oct 3, 2019 · 3 comments · Fixed by #1639

Comments

@jakebailey
Copy link
Member

commented Oct 3, 2019

Typeshed defines in sys.pyi:

_ExcInfo = Tuple[Type[BaseException], BaseException, TracebackType]]
_OptExcInfo = Union[_ExcInfo, Tuple[None, None, None]]

def exc_info() -> _OptExcInfo: ...

With the TypeShedSysExcInfo test which checks the return value of exc_info, this fails with:

"BaseException" with a length of 13, but 
    "Union[Tuple[Type[BaseException], BaseException, TracebackType], Tuple[Unknown]]" has a length of 79, differs near "Uni" (index 0).

As it's unpacking the first item incorrectly, likely because at the top level it's a union.

Copy that same code out into its own typing test:

_ExcInfo = Tuple[Type[BaseException], BaseException, TracebackType]]
_OptExcInfo = Union[_ExcInfo, Tuple[None, None, None]]

x: _ExcInfo
y: _OptExcInfo

a, b, c = u

And now it complains about x:

 Expected Type.Name to be 
    "Tuple[Type[BaseException], BaseException, TracebackType]" with a length of 56, but 
    "Tuple[BaseException, Unknown]" has a length of 29, differs near "Bas" (index 6).

So the tuple type parameters aren't right either.

Needed for #1371.

@jakebailey jakebailey self-assigned this Oct 3, 2019
@jakebailey jakebailey added this to the October 2019.1 milestone Oct 3, 2019
@jakebailey

This comment has been minimized.

Copy link
Member Author

commented Oct 3, 2019

My second example is actually broken because I forgot to get Type from typing, and define TracebackType.

from typing import Union, Tuple, Type

class TracebackType: ...

_ExcInfo = Tuple[Type[BaseException], BaseException, TracebackType]]
_OptExcInfo = Union[_ExcInfo, Tuple[None, None, None]]

x: _ExcInfo
y: _OptExcInfo

a, b, c = u

Now fails at y because:

Expected Type.Name to be 
    "Union[Tuple[Type[BaseException], BaseException, TracebackType], Tuple[None, None, None]]" with a length of 88, but 
    "Union[Tuple[Type[BaseException], BaseException, TracebackType], Tuple[Unknown]]" has a length of 79, differs near "Unk" (index 70).
@jakebailey

This comment has been minimized.

Copy link
Member Author

commented Oct 3, 2019

From the typing docs:

Note that None as a type hint is a special case and is replaced by type(None).

So None is a legal type parameter, but we're discarding it inconsistently.

@jakebailey

This comment has been minimized.

Copy link
Member Author

commented Oct 4, 2019

Split out the None thing to #1624, since I think this issue will end up being to handle unpacking a union of tuples.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant
You can’t perform that action at this time.