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 typed client options #96

Merged
merged 7 commits into from
Dec 17, 2021

Conversation

joeriddles
Copy link
Contributor

Closes #50

This PR:

  • Adds more type hints throughout.
  • Adds typed supabase Client options in the form of ClientOptions.
  • Adds a test.ps1 file that is equivalent to test.sh, to more easily run tests on Windows.

@joeriddles
Copy link
Contributor Author

I ran pre-commit on my end and everything is looking good. I did have to make a commit to fix all the line-endings. Setting core.autocrlf = true should fix this in the future.

> pre-commit run --all-files
pre-commit run --all-files
Trim Trailing Whitespace.................................................Passed
Check for added large files..............................................Passed
Mixed line ending........................................................Passed
isort....................................................................Passed
autoflake................................................................Passed
black....................................................................Passed

@dreinon
Copy link
Contributor

dreinon commented Dec 15, 2021

@joeriddles thanks for the contribution! Tests are failing, could you take a look whenever you have time, please?

Thanks!

@joeriddles
Copy link
Contributor Author

@dreinon fixed the tests! Looks like they're passing on my machine. I'm not exactly sure what xfailed and xpassed mean, but they're not red.

collected 57 items

tests\test_client.py xxxxxxxxxxxxxxxxXXXxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...s                                                                                     [ 92%]
tests\test_client_options.py ..                                                                                                                                [ 96%] 
tests\test_dummy.py ..                                                                                                                                         [100%]

=== 7 passed, 1 skipped, 46 xfailed, 3 xpassed in 4.67s ===

@dreinon dreinon requested a review from a team December 16, 2021 00:14
@dreinon
Copy link
Contributor

dreinon commented Dec 16, 2021

@leynier @anand2312 can you review this too please?

"""A storage provider. Used to store the logged in session."""
local_storage: Dict[str, Any] = dataclasses.field(default_factory=lambda: {})

"""Options passed to the realtime-js instance"""
Copy link
Contributor

Choose a reason for hiding this comment

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

Realtime-py?

Copy link
Contributor Author

@joeriddles joeriddles Dec 16, 2021

Choose a reason for hiding this comment

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

Realtime-py?

Not sure I understand this comment. Is ClientOptions missing some realtime_py values?

Copy link
Contributor

Choose a reason for hiding this comment

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

The existing comment says realtime-js, I'm guessing dreinon is asking you to change that to realtime-py

@dreinon
Copy link
Contributor

dreinon commented Dec 16, 2021

@dreinon fixed the tests! Looks like they're passing on my machine. I'm not exactly sure what xfailed and xpassed mean, but they're not red.

collected 57 items

tests\test_client.py xxxxxxxxxxxxxxxxXXXxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...s                                                                                     [ 92%]
tests\test_client_options.py ..                                                                                                                                [ 96%] 
tests\test_dummy.py ..                                                                                                                                         [100%]

=== 7 passed, 1 skipped, 46 xfailed, 3 xpassed in 4.67s ===

xfails are tests that are expected to fail, but xpasses are tests that are expected to fail but passed (which shouldn't be the case). Could you look into these cases too please @joeriddles?

@dreinon
Copy link
Contributor

dreinon commented Dec 16, 2021

Well, actually, these xpasses are happening in a file this PR does not touch, so no worries about that.

@dreinon
Copy link
Contributor

dreinon commented Dec 16, 2021

What I would actually like you to check is the two refactors sourcery proposes in PR #97, last commit. These cases are when variables are inmediately returned, sourcery asks you to return its value directly.

@joeriddles
Copy link
Contributor Author

What I would actually like you to check is the two refactors sourcery proposes in PR #97, last commit. These cases are when variables are inmediately returned, sourcery asks you to return its value directly.

Sure, made the changes, though one of sourcery's suggested changes was for part of a function I didn't touch. Regardless, made the small tweaks.

supabase/client.py Outdated Show resolved Hide resolved
supabase/lib/storage_client.py Outdated Show resolved Hide resolved
@joeriddles
Copy link
Contributor Author

@anand2312 thanks for adding those type hints

@dreinon
Copy link
Contributor

dreinon commented Dec 16, 2021

Perfect, so let's wait for @leynier 's review and then we'll ve ready to merge :)

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Dec 16, 2021

Sourcery Code Quality Report

❌  Merging this PR will decrease code quality in the affected files by 0.13%.

Quality metrics Before After Change
Complexity 0.71 ⭐ 0.72 ⭐ 0.01 👎
Method Length 22.74 ⭐ 22.42 ⭐ -0.32 👍
Working memory 5.55 ⭐ 5.50 ⭐ -0.05 👍
Quality 86.45% 86.32% -0.13% 👎
Other metrics Before After Change
Lines 219 210 -9
Changed files Quality Before Quality After Quality Change
supabase/client.py 84.33% ⭐ 84.06% ⭐ -0.27% 👎
supabase/lib/constants.py 99.83% ⭐ 100.00% ⭐ 0.17% 👍
supabase/lib/storage_client.py 97.67% ⭐ 97.67% ⭐ 0.00%
tests/conftest.py 93.85% ⭐ 92.70% ⭐ -1.15% 👎

Here are some functions in these files that still need a tune-up:

File Function Complexity Length Working Memory Quality Recommendation

Legend and Explanation

The emojis denote the absolute quality of the code:

  • ⭐ excellent
  • 🙂 good
  • 😞 poor
  • ⛔ very poor

The 👍 and 👎 indicate whether the quality has improved or gotten worse with this pull request.


Please see our documentation here for details on how these metrics are calculated.

We are actively working on this report - lots more documentation and extra metrics to come!

Help us improve this quality report!

@joeriddles
Copy link
Contributor Author

I also added py.typed to implement PEP561, "Distributing and Packaging Type Information".

@leynier
Copy link
Member

leynier commented Dec 17, 2021

LGTM! Thanks for the contribution @joeriddles

@dreinon dreinon merged commit 5b5850f into supabase-community:develop Dec 17, 2021
@joeriddles joeriddles deleted the add-client-options branch December 17, 2021 01:35
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.

Type Hints for Supabase-py
5 participants