Skip to content

Update select and selectors to use _HasFileno protocol#3057

Merged
JelleZijlstra merged 1 commit intopython:masterfrom
Eric-Arellano:selectors-protocol
Jun 15, 2019
Merged

Update select and selectors to use _HasFileno protocol#3057
JelleZijlstra merged 1 commit intopython:masterfrom
Eric-Arellano:selectors-protocol

Conversation

@Eric-Arellano
Copy link
Contributor

At the time of creating type stubs for the stdlib select.pyi and selectors.pyi, there was no support for structural subtyping via protocols. So, the stubs had to use Any (no type safety) and socket.socket (only a subset of supported types).

Now that protocols are widely supported (https://www.python.org/dev/peps/pep-0544/ and https://mypy-lang.blogspot.com/2017/10/mypy-0530-released.html), the exact types can be expressed properly.

Here, we use the naming convention established in faulthandler.pyi:

class _HasFileno(Protocol):
def fileno(self) -> int: ...

This properly fixes #482.

@JelleZijlstra JelleZijlstra merged commit d36a519 into python:master Jun 15, 2019
@Eric-Arellano Eric-Arellano deleted the selectors-protocol branch June 16, 2019 00:23
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.

How do I type a "file object"?

2 participants