create_server returns a Server, not AbstractServer#3131
create_server returns a Server, not AbstractServer#3131srittau merged 3 commits intopython:masterfrom
Conversation
|
mypy is unhappy with this for reasons I don't fully understand. Maybe if you make these functions use |
|
Oh, I wonder if it's because there is another typeshed/stdlib/3/asyncio/events.pyi Lines 121 to 125 in dad16f2 AbstractServer and this base loop returns a Server?
|
| @coroutine | ||
| def create_unix_server(self, protocol_factory: _ProtocolFactory, path: str, *, | ||
| sock: Optional[socket] = ..., backlog: int = ..., ssl: _SSLContext = ...) -> Generator[Any, None, AbstractServer]: ... | ||
| sock: Optional[socket] = ..., backlog: int = ..., ssl: _SSLContext = ...) -> Generator[Any, None, Server]: ... |
There was a problem hiding this comment.
create_unix_server() is actually not implemented by BaseEventLoop. Just tested this and it throws a NotImplementedError when called. So they should just be removed from here.
There was a problem hiding this comment.
Removed. I believe the same is true of create_unix_connection and it should probably be removed as well. I haven't done that yet (as it's a bit of a separate issue than what this PR is intending) but can easily do so if you'd like.
There was a problem hiding this comment.
@scottbelden I think removing create_unix_connection as well would be a good idea. But that leaves us with the problem that mypy complains that create_unix_* is missing, because it's abstract in the base class and BaseEventLoop, which is concrete, does not implement it. I see several possible solutions:
- Restore
create_unix_serveras a copy ofAbstractEventLoops signature and leavecreate_unix_connectionalone. I don't like this, because it doesn't reflect reality. - Add
ABCMetaas metaclass toBaseEventLoop. That even worse, sinceBaseEventLoopis clearly not meant to be abstract and this can cause problems down the line. - Just add
# type: ignoreto line 22 to force this error to go away. Works, but it's a bit rough, and means that classes deriving fromBaseEventLoopneed to do the same. - Remove
@abstractmethodfromAbstractEventLoop.create_unix_serverandcreate_unix_connection(and instead add a comment with an explanation). I prefer this solution as these methods are clearly not abstract in the sense that they need to be implemented by any concrete sub-class (which is what@abstractmethodimplies).
I'd like to hear @JelleZijlstra's thoughts about this, though.
There was a problem hiding this comment.
So if I understand correctly, the problem is:
- The base abstract class,
AbstractEventLoop, has an abstract methodcreate_unix_server BaseEventLoopis meant to be concrete but does not actually implementcreate_unix_server.
But the second part isn't true: BaseEventLoop has a number of unimplemented methods, and the actual runtime type of an event loop is asyncio.unix_events._UnixSelectorEventLoop for me (and presumably some other class on Windows). So it should be fine to add ABCMeta to BaseEventLoop.
There was a problem hiding this comment.
Ah, if BaseEventLoop is not actually meant to be instantiated, I agree.
There was a problem hiding this comment.
If I understand correctly, class BaseEventLoop(AbstractEventLoop) should be changed to class BaseEventLoop(AbstractEventLoop, metaclass=ABCMeta). Is this correct? Should the create_unix_* methods still be removed from BaseEventLoop?
There was a problem hiding this comment.
@scottbelden Yes to both questions. Hopefully that will resolve the build failure.
There was a problem hiding this comment.
(Also, it's easier for us if you don't force-push. We will squash merge anyway.)
3a862bf to
e6d69eb
Compare
|
Could you fix the merge conflict and the Travis failure? |
|
Sorry, was away for a bit. I believe I addressed the comments and merged with master. It's running through CI right now. |
I believe this should resolve my current error:
error: Module 'asyncio.base_events' has no attribute 'Server'Also, looking at the implementation of
create_serverand a few other functions, it seems like they should return aServer, not anAbstractServer: https://github.com/python/cpython/blob/9cd39b16e2655f748f7aa8d20bca4812da00ba70/Lib/asyncio/base_events.py#L1466-L1476