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

select.poll is not available on windows #13243

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

tungol
Copy link
Contributor

@tungol tungol commented Dec 13, 2024

It's also a function, but mypy-primer shows that it's in use as a type in the ecosystem, so I think we should keep that fiction.

This comment has been minimized.

@brianschubert
Copy link
Contributor

Hmm, this is messy. While select.poll is a function, it returns an object whose type is named select.poll:

>>> type(select.poll())
<class 'select.poll'>

Plus the select docs document the methods on poll objects as though there is a class named poll: https://docs.python.org/3/library/select.html#polling-objects

@tungol
Copy link
Contributor Author

tungol commented Dec 13, 2024

Yeah, it's not the only case where that happens in the stdlib; mostly in older C modules. It's a tradeoff of accuracy versus ease of typing, and we've come down on both sides of that in typeshed depending on the situation.

I was thinking that maybe the recommendation to use selectors.* over select.* meant that we could get away with accuracy here, but I do see that we have one hit in mypy-primer of a project using select.poll as a type. Here's their code:

class SocketChecker:
    def __init__(self) -> None:
        self._poller: Optional[select.poll]
        if _HAVE_POLL:
            self._poller = select.poll()
        else:
            self._poller = None

So we should probably keep this as a type. I suspect it's too niche to be worthwhile, but it'd be neat if we had a decorator to use on functions to indicate that if this function is used as a type, then the return type of the function is what's meant. We could resolve a dozen or so compromises in typeshed with something like that.

@tungol tungol changed the title select.poll is a function that returns a type, not the type select.poll is not available on windows Dec 13, 2024

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

Copy link
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

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