Skip to content

Accept socket.socket in fcntl functions #3582

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

Closed
wants to merge 1 commit into from

Conversation

dfarley1
Copy link
Contributor

@dfarley1 dfarley1 commented Jan 7, 2020

Sockets have a .fileno() method so they work fine here.

Sockets have a `.fileno()` method so they work fine here.
@hauntsaninja
Copy link
Collaborator

Might be better to use a protocol?

@dfarley1
Copy link
Contributor Author

dfarley1 commented Jan 7, 2020

Looks like there's already several _HasFileno protocols and _FileObject/_FileDescriptor types defined (sometimes with conflicting definitions!). Is there anywhere "global" we can consolidate the different definitions?

It looks like asyncore.file_dispatcher and termios also have the same issue, I'll add the protocol there as well.

Edit: Follow-up question: assuming we can centralize the definition should we make all classes with a fileno() method inherit from that protocol? There are a ton of them so reducing duplication would be great. Maybe in io if no where else?

@srittau
Copy link
Collaborator

srittau commented Jan 7, 2020

Currently we don't have a central location for protocols like these. But I think we could start adding this one to io and marking it @type_check_only. I don't see the point in deriving concrete classes from protocols, after all protocols were designed to be used ad-hoc.

CC @JelleZijlstra

@JelleZijlstra
Copy link
Member

Sounds good. Maybe we could add something like a _types module to typeshed to hold these typing-only types; it could also be used for python/mypy#8240.

@dfarley1
Copy link
Contributor Author

dfarley1 commented Jan 7, 2020

Where would the _types module live? At the top level stdlib/2and3/_types.pyi?

@JelleZijlstra
Copy link
Member

Yes

@dfarley1
Copy link
Contributor Author

dfarley1 commented Jan 7, 2020

Maybe a dumb question but how do you import across "versions"? Will files under stdlib/3 be able to do from _types import ... if it's under 2and3? I can't seem to find where the pythonpath is setup

@JelleZijlstra
Copy link
Member

Yes, that should work. The path logic is hardcoded in type checkers, so mypy knows to look at all of stdlib/2and3/, stdlib/3/, etc. when it is typechecking Python 3 code.

@dfarley1
Copy link
Contributor Author

dfarley1 commented Jan 7, 2020

Continuing on #3584, I changed branch names on my desktop

@dfarley1 dfarley1 closed this Jan 7, 2020
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.

4 participants