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

fix sys.exc_info return type #246

Merged
merged 1 commit into from
Jun 6, 2016
Merged

fix sys.exc_info return type #246

merged 1 commit into from
Jun 6, 2016

Conversation

tharvik
Copy link
Contributor

@tharvik tharvik commented Jun 3, 2016

sys.exc_info can also return a Tuple of None

If no exception is being handled anywhere on the stack, a tuple containing three None values is returned.

@gvanrossum
Copy link
Member

I don't think this will work. If you have code like

a, b, c = sys.exc_info()

then it will complain with an error:

__tmp__.py:4: error: 'Union[Tuple[builtins.type, builtins.BaseException, types.TracebackType], Tuple[void, void, void]]' object is not iterable

@gvanrossum
Copy link
Member

My suggestion is to use Tuple[Optional[type], Optional[BaseException], Optional[TracebackType]] as the return type.

@tharvik
Copy link
Contributor Author

tharvik commented Jun 6, 2016

then it will complain with an error:

__tmp__.py:4: error: 'Union[Tuple[builtins.type, builtins.BaseException, types.TracebackType], Tuple[void, void, void]]' object is not iterable

then mypy is wrong, Tuple is iterable, thus the Union should also be iterable. Seems to be already reported on mypy.

For now, I'll use your suggestion, and add a TODO.

@tharvik tharvik force-pushed the fix_sys branch 2 times, most recently from 4f7250c to 7b76363 Compare June 6, 2016 07:12
@gvanrossum gvanrossum merged commit c40a260 into python:master Jun 6, 2016
@tharvik tharvik deleted the fix_sys branch August 8, 2016 06:47
bluetech added a commit to bluetech/typeshed that referenced this pull request Jul 11, 2019
I believe that either all of the items are None or none of them are.
Reflect that in the type.

This was attempted initially in
python#246
but apparently mypy didn't allow unpacking given such a union, but it
does now (checked with mypy 0.711).

The (incorrect) TODO from that PR was removed in commit
25ac4d6 but the commit message noted
that this change is desirable.
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.

None yet

2 participants