-
Notifications
You must be signed in to change notification settings - Fork 403
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 typing to _ConnectionParameters
and related functions
#1199
base: master
Are you sure you want to change the base?
Conversation
Based on review in #1198 I have swapped out the stringified annotations for non-stringified behind a I also had to rebase and force push due to merge conflicts. |
dd3b924
to
294e6bc
Compare
@@ -167,7 +166,9 @@ def _read_password_from_pgpass( | |||
return None | |||
|
|||
|
|||
def _validate_port_spec(hosts, port): | |||
def _validate_port_spec( | |||
hosts: Sequence[object], port: typing.Union[int, typing.List[int]] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hosts: Sequence[object], port: typing.Union[int, typing.List[int]] | |
hosts: typing.List[str], port: typing.Union[int, typing.List[int]] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did this because of line 172. If your suggestion is correct we can remove the else
branch. Since I didn't want to change the functionality of the code too much I just added what the code is able to handle instead of what it likely should be, if that makes sense.
Would you want me to change this? Or is keeping as is fine? If it is the latter, could you press the Merge button? :)
This adds typing to an important
NamedTuple
in this module that will allow using types in a lot of other functions that have a reference to this object.The final type looks very similar to what was suggested in #577 but this is based on the paths that the code can actually take. As with other PRs the strategy is simple: start with the lowest function in the call chain to see if the code can tell you what types it should accept and propagate upwards until you reach the
NamedTuple
.The most controversial change is probably
_ConnectionParameters.ssl
. This is because of the code path where we setsslmode = SSLMode.disable
. It is a bit annoying but that code path means thatssl
never gets reassigned and therefore will be whatever_parse_connect_dsn_and_args
accepts. We should probably change that to beNone
but I don't want to introduce behaviour changes in these PRs.The two actual runtime changes are straightforward and any mistakes in the typing we can (of course) always rectify later.