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

Add typings #366

Merged
merged 3 commits into from Feb 9, 2021
Merged

Add typings #366

merged 3 commits into from Feb 9, 2021

Conversation

@bryanforbes
Copy link
Contributor

@bryanforbes bryanforbes commented Nov 2, 2020

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: ignore comment:

  • remove_signal_handler() returns a bool and typeshed has this method returning None in AbstractEventLoop. 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_delay and interleave) and since uvloop.Loop.create_connection() doesn't allow those arguments, the two methods are incompatible. This may be unavoidable.

References #358

def can_write_eof(self) -> bool: ...
def abort(self) -> None: ...

class _Server(asyncio.AbstractServer):

This comment has been minimized.

@1st1

1st1 Nov 2, 2020
Member

I'm curious why we need this as opposed to simply using asyncio.AbstractServer?

This comment has been minimized.

@bryanforbes

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.

This comment has been minimized.

@1st1

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.

This comment has been minimized.

@bryanforbes

bryanforbes Nov 2, 2020
Author Contributor

That's good to know! I'll go back over this PR with that in mind.

This comment has been minimized.

@bryanforbes

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].

This comment has been minimized.

@1st1

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.

This comment has been minimized.

@bryanforbes

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.

This comment has been minimized.

@1st1

1st1 Nov 2, 2020
Member

Yes, thanks. And we can always fix uvloop code that doesn't conform to asyncio APIs.

This comment has been minimized.

@bryanforbes

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.

@bryanforbes bryanforbes force-pushed the bryanforbes:add-typings branch from 6a2f54c to fc1b4ba Jan 1, 2021
@fantix fantix added this to New Feature in Fantix's Sorting Board Jan 20, 2021
@1st1
Copy link
Member

@1st1 1st1 commented Feb 9, 2021

@fantix We can probably merge this one too, please review.

@fantix fantix moved this from New Feature to Quick Fix in Fantix's Sorting Board Feb 9, 2021
@bryanforbes
Copy link
Contributor Author

@bryanforbes bryanforbes commented Feb 9, 2021

I can rebase this on master if it would make it easier to review. Just let me know.

@fantix
Copy link
Member

@fantix fantix commented Feb 9, 2021

@bryanforbes Yes, please! Thank you! Never mind, it's done 😃

@fantix fantix moved this from Quick Fix to Critical Path in Fantix's Sorting Board Feb 9, 2021
@fantix fantix force-pushed the bryanforbes:add-typings branch from fc1b4ba to ac3d94a Feb 9, 2021
@bryanforbes
Copy link
Contributor Author

@bryanforbes bryanforbes commented Feb 9, 2021

I have a couple of small edits to make before you merge

@fantix
fantix approved these changes Feb 9, 2021
Copy link
Member

@fantix fantix left a comment

LGTM! I'll be waiting for your edits.

@bryanforbes
Copy link
Contributor Author

@bryanforbes bryanforbes commented Feb 9, 2021

@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 # type: ignore[misc] can be removed from __init__.py.

@fantix
Copy link
Member

@fantix fantix commented Feb 9, 2021

Once those methods are changed, the # type: ignore[misc] can be removed from __init__.py.

Sounds good 👍

@fantix fantix merged commit 9426e2b into MagicStack:master Feb 9, 2021
7 checks passed
7 checks passed
@github-actions
test (3.7, ubuntu-latest) test (3.7, ubuntu-latest)
Details
@github-actions
test (3.7, macos-latest) test (3.7, macos-latest)
Details
@github-actions
test (3.8, ubuntu-latest) test (3.8, ubuntu-latest)
Details
@github-actions
test (3.8, macos-latest) test (3.8, macos-latest)
Details
@github-actions
test (3.9, ubuntu-latest) test (3.9, ubuntu-latest)
Details
@github-actions
test (3.9, macos-latest) test (3.9, macos-latest)
Details
@github-actions
Regression Tests
Details
@fantix fantix removed this from Critical Path in Fantix's Sorting Board Feb 9, 2021
@1st1
Copy link
Member

@1st1 1st1 commented Feb 9, 2021

Thanks @bryanforbes!

@bryanforbes
Copy link
Contributor Author

@bryanforbes bryanforbes commented Feb 9, 2021

Not a problem! If you ever have any typing questions, feel free to reach out to me.

@1st1
Copy link
Member

@1st1 1st1 commented Feb 9, 2021

@bryanforbes thanks! If you have time please take a look at MagicStack/immutables#54 -- another our package.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants