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 return types to client functions. #68

Merged

Conversation

melwil
Copy link
Contributor

@melwil melwil commented Mar 8, 2023

This PR aims to introduce type hints to return values for the client.

The changes are simple enough, simply adding the types as return type hints on each function in the client.

Working with the sdk is somewhat cumbersome, since I work in a typed project. The return types from the sdk are not great [see attachment], and properly resolving the typing of the responses from the sdk client should not really be necessary.

I've made a suggestion of how it could be done, but I had some trouble installing 3.7 to verify that this works as expected. I'm not sure if there were good reasons for leaving the types out, or if resolving the models leads to other problems.

image

Copy link
Contributor

@volodymyrZotov volodymyrZotov left a comment

Choose a reason for hiding this comment

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

That's a great improvement to the sdk! We definitely should use the power of types.
Unfortunately, your change in deserialize function usage won't work if pass the type as it is and not as a string. (aka list[File] instead of "list[File]" string)
I left a single comment about that, but actually, all the deserialize usages should be reverted in order to make it work.

src/onepasswordconnectsdk/client.py Outdated Show resolved Hide resolved
Copy link
Contributor

@williamhpark williamhpark left a comment

Choose a reason for hiding this comment

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

Thanks for this addition! 😄 I suggested a few minor changes, let me know if you would like me to add any additional context

src/onepasswordconnectsdk/client.py Outdated Show resolved Hide resolved
src/onepasswordconnectsdk/client.py Outdated Show resolved Hide resolved
src/onepasswordconnectsdk/client.py Show resolved Hide resolved
src/onepasswordconnectsdk/client.py Outdated Show resolved Hide resolved
@melwil
Copy link
Contributor Author

melwil commented Oct 23, 2023

Thanks for the review, @williamhpark ! I had missed the fact that an async client had been added. Added return types to that as well, by the way 😉

Copy link
Contributor

@williamhpark williamhpark left a comment

Choose a reason for hiding this comment

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

Two small nitpicks, but looks good to me otherwise!

src/onepasswordconnectsdk/async_client.py Outdated Show resolved Hide resolved
src/onepasswordconnectsdk/async_client.py Outdated Show resolved Hide resolved
@melwil melwil force-pushed the improvement/return-types-for-client branch from 9c3d002 to 5eeab2f Compare October 23, 2023 23:23
@melwil
Copy link
Contributor Author

melwil commented Oct 24, 2023

I think the errors in the test run were related to the typing of list and dict, the typing style changed in 3.9 and so the tests in 3.8 failed with the newer syntax.

@melwil
Copy link
Contributor Author

melwil commented Oct 24, 2023

Same for the return types needing Union. I should really take another stab at getting 3.8 to work properly 😅

@melwil
Copy link
Contributor Author

melwil commented Oct 24, 2023

Seems like what fails now is uploading the code coverage generated by the test. Not sure if my branch impacted this? Would a merge with main be needed or something?

@williamhpark
Copy link
Contributor

williamhpark commented Oct 24, 2023

@melwil Thank you for catching and making those changes! Hm interesting, I'm currently looking into what's causing that to fail.

@williamhpark
Copy link
Contributor

williamhpark commented Oct 24, 2023

@melwil Re-running the jobs did the trick! Seems like it was just a bit flaky.

Unfortunately, merging is currently blocked because commit 5964657 was unverified. I noticed that your later commits were successfully signed - did you perhaps use a different signing key for the unverified commit that wasn't configured in GitHub?

@melwil
Copy link
Contributor Author

melwil commented Oct 24, 2023

did you perhaps use a different signing key for the unverified commit that wasn't configured in Git?

That commit was made a long time ago, I didn't have signing keys for github set up back then 😅

I could check if I can manage to sign it retroactively. Alternatively, if I turn off strict mode, would that help? 🤔

@williamhpark
Copy link
Contributor

@melwil I see! IIRC, when this had happened to me in the past, I ended up having to overwrite my unsigned commits. This Stack Overflow post can hopefully provide some more insight.

@melwil melwil force-pushed the improvement/return-types-for-client branch from 8ae6b03 to 15a8f05 Compare October 24, 2023 17:05
@melwil
Copy link
Contributor Author

melwil commented Oct 24, 2023

Ok, better run the tests one more time for this, bit messy with the rebase considering the age of that first commit. Looking over the changes again might be a good idea too. But all signed now.

@melwil
Copy link
Contributor Author

melwil commented Oct 24, 2023

It looks good to me, apart from that one mistake with the imports.

@codecov-commenter
Copy link

Codecov Report

Attention: 2 lines in your changes are missing coverage. Please review.

Comparison is base (5f8ffd8) 77.05% compared to head (094116e) 77.13%.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #68      +/-   ##
==========================================
+ Coverage   77.05%   77.13%   +0.07%     
==========================================
  Files          27       27              
  Lines        1931     1933       +2     
==========================================
+ Hits         1488     1491       +3     
+ Misses        443      442       -1     
Files Coverage Δ
src/onepasswordconnectsdk/async_client.py 65.16% <100.00%> (+0.22%) ⬆️
src/onepasswordconnectsdk/client.py 63.95% <93.54%> (+0.79%) ⬆️

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@williamhpark
Copy link
Contributor

@melwil I took a look again and there was one thing that I think I missed in my initial review that I left a comment on. Besides that, everything looks good to me!

@williamhpark williamhpark merged commit 8b31f93 into 1Password:main Oct 24, 2023
1 check passed
@melwil melwil deleted the improvement/return-types-for-client branch October 26, 2023 16:13
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.

5 participants