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 typing for uuid4() #2164

Closed
wants to merge 5 commits into from

Conversation

evenicoulddoit
Copy link

What does this change

  • Adds proper type support for uuid4(), so that static type checkers understand the return type based on the inputs

What was wrong

  • Working with Faker in an environment using a static type checker such as MyPy / Pyright is frustrating when using uuid4(), because these tools rightly point out that the return type is one of UUID | str | bytes

How this fixes it

  • This adds overload typing so that the output is deterministic

Checklist

  • I have read the documentation about CONTRIBUTING
  • I have read the documentation about Coding style
  • I have run make lint

Copy link
Collaborator

@fcurella fcurella left a comment

Choose a reason for hiding this comment

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

Thank you!

We must also update the generate_stubs.py script to support the @overload decorator.

See also #2046, #2042

@evenicoulddoit
Copy link
Author

@fcurella done. Also updated the dependency management to make it easier to consistently develop

@@ -8,13 +8,16 @@ mypy:
mypy --install-types --non-interactive --config mypy.ini faker

black:
black --line-length 120 .
Copy link
Author

Choose a reason for hiding this comment

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

This is now defined in pyproject.toml and needn't be tracked elsewhere.

Comment on lines +18 to +19
black faker/proxy.pyi
isort faker/proxy.pyi
Copy link
Author

Choose a reason for hiding this comment

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

Unless these are applied you don't actually see your changes properly.

@evenicoulddoit
Copy link
Author

@fcurella the CI process uses the master branch to determine the checks. I can't fix the typing until #2171 is merged in.

@evenicoulddoit evenicoulddoit mentioned this pull request Feb 7, 2025
3 tasks
@fcurella
Copy link
Collaborator

Done in 9c8b132

@fcurella fcurella closed this Feb 13, 2025
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