Skip to content

Fix accepted types in select.select#15757

Merged
srittau merged 2 commits into
mainfrom
fix-select-select
May 11, 2026
Merged

Fix accepted types in select.select#15757
srittau merged 2 commits into
mainfrom
fix-select-select

Conversation

@sobolevn
Copy link
Copy Markdown
Member

No errors happen in type checking time for select(['a'], ['b'], ['c']). See https://mypy-play.net/?gist=2a5c9fcecebd7dbfd6f9823f605da0e5

Not any values are allowed in select.select. It only allows int | HasFileno items. See:

>>> from select import select
... 
... select(['a', 'b'], [], [])
... 
Traceback (most recent call last):
  File "<python-input-0>", line 3, in <module>
    select(['a', 'b'], [], [])
    ~~~~~~^^^^^^^^^^^^^^^^^^^^
TypeError: argument must be an int, or have a fileno() method.
>>> 
KeyboardInterrupt
>>> 
                                                                                           
(.venv) ~/Desktop/cpython  issue-149609 ✔                                                 
» python  
Python 3.14.2 (main, Mar 16 2026, 20:11:03) [Clang 17.0.0 (clang-1700.6.3.2)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from select import select
... 
... select(['a'], [], [])
... 
Traceback (most recent call last):
  File "<python-input-2>", line 3, in <module>
    select(['a'], [], [])
    ~~~~~~^^^^^^^^^^^^^^^
TypeError: argument must be an int, or have a fileno() method.
>>> from select import select
... 
... select([], ['a'], [])
... 
Traceback (most recent call last):
  File "<python-input-0>", line 3, in <module>
    select([], ['a'], [])
    ~~~~~~^^^^^^^^^^^^^^^
TypeError: argument must be an int, or have a fileno() method.
>>> from select import select
... 
... select([], [], ['a'])
... 
Traceback (most recent call last):
  File "<python-input-1>", line 3, in <module>
    select([], [], ['a'])
    ~~~~~~^^^^^^^^^^^^^^^
TypeError: argument must be an int, or have a fileno() method.

Why is that?

  1. All passed lists are passed to seq2set: https://github.com/python/cpython/blob/53c3dd9a8d79a331764147b7b7b01f9d0a8bce71/Modules/selectmodule.c#L344-L349
  2. seq2set calls PyObject_AsFileDescriptor on list items https://github.com/python/cpython/blob/53c3dd9a8d79a331764147b7b7b01f9d0a8bce71/Modules/selectmodule.c#L168
  3. It requires int or HasFileno type: https://github.com/python/cpython/blob/53c3dd9a8d79a331764147b7b7b01f9d0a8bce71/Objects/fileobject.c#L172-L182

@github-actions

This comment has been minimized.

@sobolevn
Copy link
Copy Markdown
Member Author

@github-actions
Copy link
Copy Markdown
Contributor

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

spark (https://github.com/apache/spark)
+ python/pyspark/daemon.py:193: error: Value of type variable "_R" of "select" cannot be "object"  [type-var]

operator (https://github.com/canonical/operator)
+ ops/pebble.py:1902: error: Value of type variable "_R" of "select" cannot be "object"  [type-var]

@srittau srittau merged commit bcb6399 into main May 11, 2026
56 checks passed
@srittau srittau deleted the fix-select-select branch May 11, 2026 10:06
tkem pushed a commit to tkem/typeshed that referenced this pull request May 17, 2026
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.

2 participants