_HasFileno in platform/asyncio.py must be hashable because instances are used as dictionary key#3622
_HasFileno in platform/asyncio.py must be hashable because instances are used as dictionary key#3622jonathandung wants to merge 3 commits into
_HasFileno in platform/asyncio.py must be hashable because instances are used as dictionary key#3622Conversation
|
Thanks! Looks good to me aside from the fact that the linter requires a blank line between the method definitions. |
|
Hmm, so this change can only be made cleanly (without ignoring the override violation) if it's made in lockstep with an update to typeshed? That's unfortunate. Is there some way to sequence the changes so they can be applied in order? (For example, change the typing of asyncio.AbstractEventLoop to require Is there some way for me to reference the type used by AbstractEventLoop.add_reader instead of redefining the protocol here? I don't mind the type:ignore here too much, but I wouldn't want to put something like that in for a typeshed change that may not merge for a long time (if at all - I'm sympathetic to the idea that hashability is too weird to be worth modeling in the static type layer since |
|
The Reading through the CPython source, it seems that the |
|
If the def _fileobj_to_fd(fileobj):
"""Return a file descriptor from a file object.
Parameters:
fileobj -- file object or file descriptor
Returns:
corresponding file descriptor
Raises:
ValueError if the object is invalid
"""
if isinstance(fileobj, int):
fd = fileobj
else:
try:
fd = int(fileobj.fileno())
except (AttributeError, TypeError, ValueError):
raise ValueError("Invalid file object: "
"{!r}".format(fileobj)) from None
if fd < 0:
raise ValueError("Invalid file descriptor: {}".format(fd))
return fdTaken from |
Parent: python/typeshed#15754.