FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Add typing to two objects in `connection_utils` by DanielNoord · Pull Request #1198 · MagicStack/asyncpg · GitHub

Add typing to two objects in connection_utils - #1198

Merged
elprans merged 3 commits into
MagicStack:masterfrom
DanielNoord:type-connection-utils
Oct 29, 2024
Merged

Add typing to two objects in connection_utils#1198
elprans merged 3 commits into
MagicStack:masterfrom
DanielNoord:type-connection-utils

Conversation

Copy link
Copy Markdown
Contributor

I noticed that it would be very useful to have a fully typed connection_utils as it is the core for a lot of other modules that interact with the connect.Connection.

This just adds some basic parameter annotation that is pretty straightforward. I have also decided to be pragmatic and add a TODO for stuff that is just too hard right now. We can always revisit cases like this if we ever do want to enable a type checker. In the meantime, having callers of the internal function _create_ssl_connection get the correct type already helps with typing the public API correctly.

DanielNoord force-pushed the type-connection-utils branch from 7e298d5 to 76105cc Compare October 23, 2024 07:23

Copy link
Copy Markdown
Contributor Author

Sorry about that! I didn't have mypy and flake8 in my virtualenv so the linter tests didn't run. This is now fixed and I ran the tests locally. This should now pass CI :)

Copy link
Copy Markdown
Contributor Author

The test failure might be a fluke? I don't really understand why the changes in this PR would only break Windows but not Linux or on other versions of Python for Windows.

elprans commented Oct 23, 2024

Copy link
Copy Markdown
Member

The test failure might be a fluke?

Yeah it's a flake.

Comment thread asyncpg/connect_utils.py Outdated
# TODO: The return type is a specific combination of subclasses of
# asyncio.protocols.Protocol that we can't express. For now, having the
# return type be dependent on signature of the factory is an improvement
protocol_factory: "Callable[[], _ProctolFactoryR]",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality
Suggested change
protocol_factory: "Callable[[], _ProctolFactoryR]",
protocol_factory: Callable[[], _ProctolFactoryR],

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

That's not possible sadly. Callable isn't subscribtable at runtime like this on Python 3.8. See earlier CI runs in which CI complained about this.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

For compatibility you want typing.Callable, not collections.abc.Callable

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

In later versions collections is preferred though. Isn't the use of stringified annotations the way to get compatibility?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

If you add from __future__ import annotations to the top of the file, you won't have to use strings in the annotation (and importing from collections.abc will also work)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Also fine with me, @elprans what has your preference?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Yeah, do that please.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Fixed!

DanielNoord requested a review from elprans October 23, 2024 16:14

Copy link
Copy Markdown
Contributor Author

Anything else missing from this PR that I can help with? Do you want me to squash the commits or are they good like this?

elprans left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Looks good, thanks!

elprans merged commit a273e0e into MagicStack:master Oct 29, 2024
DanielNoord deleted the type-connection-utils branch October 29, 2024 20:14
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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.

3 participants


Back | FazBrowse Home | New Git URL