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: adjusted type hints for UUID when uuid-utils is not installed #133

Merged
merged 8 commits into from
Feb 19, 2024

Conversation

cofin
Copy link
Member

@cofin cofin commented Feb 19, 2024

This PR addresses an issue with type hints when uuid-utils is not installed.

❯ pdm run pip uninstall uuid-utils
Found existing installation: uuid_utils 0.6.1
Uninstalling uuid_utils-0.6.1:
  Would remove:
    .../.venv/lib/python3.12/site-packages/uuid_utils-0.6.1.dist-info/*
    .../.venv/lib/python3.12/site-packages/uuid_utils/*
Proceed (Y/n)? y
  Successfully uninstalled uuid_utils-0.6.1
❯ pdm run pyright -p pyproject.toml advanced_alchemy/base.py
0 errors, 0 warnings, 0 informations 
❯ pdm run pyright -p pyproject.toml advanced_alchemy/types/guid.py
0 errors, 0 warnings, 0 informations 

@cofin cofin requested review from a team as code owners February 19, 2024 15:44
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

PR Type: Refactoring

PR Summary: This pull request focuses on adjusting type hints and import logic for UUID handling within the advanced_alchemy project, specifically when the optional dependency uuid-utils is not installed. It introduces conditional imports based on the presence of uuid-utils and refines type annotations and checks throughout the affected modules to ensure compatibility and correct behavior regardless of whether uuid-utils is available.

Decision: Comment

📝 Type: 'Refactoring' - not supported yet.
  • Sourcery currently only approves 'Typo fix' PRs.
✅ Issue addressed: this change correctly addresses the issue or implements the desired feature.
No details provided.
✅ Small diff: the diff is small enough to approve with confidence.
No details provided.

General suggestions:

  • Consider using isinstance for type checks instead of comparing the class name as a string. This approach is more robust and idiomatic in Python, providing better support for inheritance and readability.
  • When casting types, especially in the context of decoding values, ensure that the input data is of the expected format to avoid runtime errors. It might be beneficial to add explicit checks or try-except blocks to handle unexpected data formats gracefully.
  • Review the use of type casting throughout the changes to ensure that they are necessary and correctly applied, particularly when dealing with external libraries or data that might not always conform to expected formats.

Thanks for using Sourcery. We offer it for free for open source projects and would be very grateful if you could help us grow. If you like it, would you consider sharing Sourcery on your favourite social media? ✨

Share Sourcery

Help me be more useful! Please click 👍 or 👎 on each comment to tell me if it was helpful.

advanced_alchemy/types/guid.py Show resolved Hide resolved
advanced_alchemy/types/guid.py Show resolved Hide resolved
@cofin cofin linked an issue Feb 19, 2024 that may be closed by this pull request
4 tasks
Copy link
Collaborator

@Alc-Alc Alc-Alc left a comment

Choose a reason for hiding this comment

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

types are fun 🙃

@cofin cofin enabled auto-merge (squash) February 19, 2024 17:46
@cofin cofin disabled auto-merge February 19, 2024 17:46
@cofin cofin merged commit 03711c6 into main Feb 19, 2024
13 checks passed
@cofin cofin deleted the uuid-utils-type-hints branch February 19, 2024 17:46
Copy link

sonarcloud bot commented Feb 19, 2024

Copy link

Documentation preview will be available shortly at https://jolt-org.github.io/advanced-alchemy-docs-preview/133

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.

Bug: UUIDPrimaryKey.id type is Unknown | UUID when uuid_utils is not installed.
2 participants