Add typings #366
Add typings #366
Conversation
| def can_write_eof(self) -> bool: ... | ||
| def abort(self) -> None: ... | ||
|
|
||
| class _Server(asyncio.AbstractServer): |
1st1
Nov 2, 2020
Member
I'm curious why we need this as opposed to simply using asyncio.AbstractServer?
I'm curious why we need this as opposed to simply using asyncio.AbstractServer?
bryanforbes
Nov 2, 2020
Author
Contributor
asyncio.AbstractServer is defined as follows in typeshed:
class AbstractServer:
sockets: Optional[List[socket]]
def close(self) -> None: ...
if sys.version_info >= (3, 7):
async def __aenter__(self: _T) -> _T: ...
async def __aexit__(self, *exc: Any) -> None: ...
def get_loop(self) -> AbstractEventLoop: ...
def is_serving(self) -> bool: ...
async def start_serving(self) -> None: ...
async def serve_forever(self) -> None: ...
async def wait_closed(self) -> None: ...
Since uvloop works on Python 3.5+ and Server defines those methods for all versions, asyncio.AbstractServer will be wrong for uvloop on Python 3.5 and 3.6.
asyncio.AbstractServer is defined as follows in typeshed:
class AbstractServer:
sockets: Optional[List[socket]]
def close(self) -> None: ...
if sys.version_info >= (3, 7):
async def __aenter__(self: _T) -> _T: ...
async def __aexit__(self, *exc: Any) -> None: ...
def get_loop(self) -> AbstractEventLoop: ...
def is_serving(self) -> bool: ...
async def start_serving(self) -> None: ...
async def serve_forever(self) -> None: ...
async def wait_closed(self) -> None: ...Since uvloop works on Python 3.5+ and Server defines those methods for all versions, asyncio.AbstractServer will be wrong for uvloop on Python 3.5 and 3.6.
1st1
Nov 2, 2020
Member
I'll be dropping support for 3.5 and 3.6. 3.5 is no longer supported by Python core devs; 3.6 is in security fixes only mode. And with 3.9 now out, uvloop will be 3.7+ only in its next release, supporting three Python versions: 3.7, 3.8, and 3.9.
I'll be dropping support for 3.5 and 3.6. 3.5 is no longer supported by Python core devs; 3.6 is in security fixes only mode. And with 3.9 now out, uvloop will be 3.7+ only in its next release, supporting three Python versions: 3.7, 3.8, and 3.9.
bryanforbes
Nov 2, 2020
Author
Contributor
That's good to know! I'll go back over this PR with that in mind.
That's good to know! I'll go back over this PR with that in mind.
bryanforbes
Nov 2, 2020
Author
Contributor
One thing to note: I think we'll still need _Server because AbstractServer.sockets is Optional[List[Socket]] and Server.sockets is List[Socket].
One thing to note: I think we'll still need _Server because AbstractServer.sockets is Optional[List[Socket]] and Server.sockets is List[Socket].
1st1
Nov 2, 2020
Member
I think we should stick to AbstractServer typing here too. That makes it easy for us to fix our Server.sockets property to follow the spec.
I think we should stick to AbstractServer typing here too. That makes it easy for us to fix our Server.sockets property to follow the spec.
bryanforbes
Nov 2, 2020
Author
Contributor
Some of these others I added while I was navigating the source. I'll make sure I validate all of these are needed when I go over this again.
Some of these others I added while I was navigating the source. I'll make sure I validate all of these are needed when I go over this again.
1st1
Nov 2, 2020
Member
Yes, thanks. And we can always fix uvloop code that doesn't conform to asyncio APIs.
Yes, thanks. And we can always fix uvloop code that doesn't conform to asyncio APIs.
bryanforbes
Jan 1, 2021
Author
Contributor
Sorry that it's taken so long to get back to this. I've updated the PR based on your feedback and rebased on master. Unfortunately, the PR checks are failing prematurely.
Sorry that it's taken so long to get back to this. I've updated the PR based on your feedback and rebased on master. Unfortunately, the PR checks are failing prematurely.
|
@fantix We can probably merge this one too, please review. |
|
I can rebase this on master if it would make it easier to review. Just let me know. |
|
@bryanforbes |
|
I have a couple of small edits to make before you merge |
|
LGTM! I'll be waiting for your edits. |
|
@fantix I committed and pushed the edits. Let me know if you have questions about them. One thing to note: the two things I pointed out in the description of this PR are still issues. Once those methods are changed, the |
Sounds good |
|
Thanks @bryanforbes! |
|
Not a problem! If you ever have any typing questions, feel free to reach out to me. |
|
@bryanforbes thanks! If you have time please take a look at MagicStack/immutables#54 -- another our package. |
This PR adds typings for use with type checkers like
mypy. Overall, this was fairly easy but two errors have to be suppressed with a# type: ignorecomment:remove_signal_handler()returns abooland typeshed has this method returningNoneinAbstractEventLoop. This seems to be an error in typeshed since the docs state it should return a bool.create_connection()in Python 3.8+ accepts two new arguments (happy_eyeballs_delayandinterleave) and sinceuvloop.Loop.create_connection()doesn't allow those arguments, the two methods are incompatible. This may be unavoidable.References #358