Skip to content

Conversation

@Dreamsorcerer
Copy link
Contributor

@Dreamsorcerer Dreamsorcerer commented Oct 26, 2024

>>> try:
...  raise TimeoutError
... except OSError as e:
...  print(e.errno)
... 
None

Code in cpython seems to always throw TimeoutError with no arguments.

@github-actions
Copy link
Contributor

Diff from mypy_primer, showing the effect of this PR on open source code:

mkosi (https://github.com/systemd/mkosi)
+ mkosi/sandbox.py:324:22: error: Argument 1 to "_exit" has incompatible type "Optional[int]"; expected "int"  [arg-type]

bokeh (https://github.com/bokeh/bokeh)
+ src/bokeh/command/util.py: note: In function "report_server_init_errors":
+ src/bokeh/command/util.py:217:40: error: Invalid index type "int | None" for "Mapping[int, str]"; expected type "int"  [index]

pytest (https://github.com/pytest-dev/pytest)
+ src/_pytest/_py/error.py:101: error: Argument 1 to "_geterrnoclass" of "ErrorMaker" has incompatible type "Optional[int]"; expected "int"  [arg-type]

cloud-init (https://github.com/canonical/cloud-init)
+ cloudinit/url_helper.py:84: error: Incompatible return value type (got "int | None", expected "int")  [return-value]

mypy (https://github.com/python/mypy)
+ mypy/modulefinder.py:780: error: Argument 1 to "strerror" has incompatible type "Optional[int]"; expected "int"  [arg-type]
+ mypy/build.py:2147: error: Argument 1 to "strerror" has incompatible type "Optional[int]"; expected "int"  [arg-type]

manticore (https://github.com/trailofbits/manticore)
+ manticore/platforms/linux.py:1767: error: Unsupported operand type for unary - ("int | None")  [operator]
+ manticore/platforms/linux.py:1780: error: Unsupported operand type for unary - ("int | None")  [operator]
+ manticore/platforms/linux.py:1810: error: Unsupported operand type for unary - ("int | None")  [operator]
+ manticore/platforms/linux.py:2340: error: Unsupported operand type for unary - ("int | None")  [operator]
+ manticore/platforms/linux.py:3512: error: Unsupported operand type for unary - ("int | None")  [operator]
+ manticore/platforms/linux.py:3525: error: Unsupported operand type for unary - ("int | None")  [operator]
+ manticore/platforms/linux.py:3560: error: Unsupported operand type for unary - ("int | None")  [operator]
+ manticore/platforms/linux.py:3578: error: Unsupported operand type for unary - ("int | None")  [operator]
+ manticore/platforms/linux.py:3590: error: Unsupported operand type for unary - ("int | None")  [operator]
+ manticore/platforms/linux.py:3668: error: Unsupported operand type for unary - ("int | None")  [operator]
+ manticore/platforms/linux.py:3681: error: Unsupported operand type for unary - ("int | None")  [operator]

@brianschubert
Copy link
Member

brianschubert commented Oct 26, 2024

Thanks! This has been discussed before, see #9864. Making a change here is currently deferred, pending some decisions on what the right CPython behavior should be

@AlexWaygood
Copy link
Member

As was predicted in #9864 (comment), it seems like this change is quite disruptive. This does also seem like exactly the kind of potential bug in your code that type checkers are meant to warn you about, however. And, as was mentioned in #9864 (comment), even if it is decided that this is a bug in CPython and a fix is applied at runtime, the fix might not be backported, and almost certainly won't be backported as far back as typeshed's lowest supported Python version (currently 3.8).

So I'm in favour of making a change to the stubs here.

@JelleZijlstra
Copy link
Member

I also agree with merging this. I'd encourage anyone reading this to send PRs to the affected projects in the mypy-primer results to fix the issue.

@AlexWaygood AlexWaygood merged commit 601ce5a into python:main Oct 27, 2024
63 checks passed
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.

5 participants