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

fix: use correct args and kwargs definitions #256

Merged
merged 1 commit into from
Aug 9, 2024

Conversation

tdstein
Copy link
Collaborator

@tdstein tdstein commented Aug 8, 2024

Various methods are defined with improper variadic positional and keyword arguments. The original intention for @overload signatures was to provide type support for pass-throughs to API query parameters or JSON arguments. Along the way, *args was introduced to these methods, assuming we wanted to match the dict function signature. This isn't very clear in practice since passing SupportsKeysAndGetItem typed variables is rare. Therefore, the *args part of the function signature is removed wherever possible. In the update(self, *args, **kwargs), we cannot remove *args since we inherit from dict, and dict enforces this method signature.

Various methods are defined with improper vardadic positional and keyword-arguments. The original intention for @overload signatures was to provide type support for passthroughs to API query parameter or json arguments. Along the way, *args was introduced to these methods assuming that we wanted to match the dict function signature. In practice, this is confusing since passing SupportsKeysAndGetItem typed variables is rare. Threfore, the *args part of the function signature is removed wherever possible. In the case of update(self, *args, **kwargs) we cannot remove *args since we inherit from dict and dict enforces this method signature.
Copy link

github-actions bot commented Aug 8, 2024

☂️ Python Coverage

current status: ✅

Overall Coverage

Lines Covered Coverage Threshold Status
1224 1190 97% 0% 🟢

New Files

No new covered files...

Modified Files

File Coverage Status
src/posit/connect/content.py 100% 🟢
src/posit/connect/groups.py 48% 🟢
src/posit/connect/metrics/shiny_usage.py 100% 🟢
src/posit/connect/metrics/usage.py 100% 🟢
src/posit/connect/metrics/visits.py 100% 🟢
src/posit/connect/permissions.py 100% 🟢
src/posit/connect/tasks.py 100% 🟢
src/posit/connect/users.py 100% 🟢
TOTAL 94% 🟢

updated for commit: 0f6841f by action🐍

@@ -229,6 +229,7 @@ def restart(self) -> None:
@overload
def update(
self,
*args,
Copy link
Collaborator

Choose a reason for hiding this comment

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

are these *args additions just for forwards / backwards compatibility?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

See below first. This is the equivalent to *, except in this case we have to include *args to match the update signature.

@@ -153,6 +153,7 @@ def find(self, *args, **kwargs) -> List[VisitEvent]:
@overload
def find_one(
self,
*,
Copy link
Collaborator

Choose a reason for hiding this comment

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

same question about the places we're adding *

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is to say, all arguments after * must be provided as keyword arguments. So, the user must call find_one(content_guid="asdf"). find_one("asdf") will throw an error.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is what we want since positional argument can change over time.

@tdstein tdstein merged commit 84371b0 into main Aug 9, 2024
31 checks passed
@tdstein tdstein deleted the tdstein/fix-overload-argument-signatures branch August 9, 2024 19:58
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.

2 participants