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

PoC: a .optional proxy that may or may not return a fake value #1867

Merged
merged 5 commits into from
Jul 7, 2023

Conversation

ligne
Copy link
Contributor

@ligne ligne commented May 26, 2023

What does this change

This adds a .optional property, that should make all the usual functions return either a fake value or None, with a customisable probability.

This was a quick and dirty lunchtime project which could use some care and attention (in particular I'm not sure about the prob=n parameter, and the tests are a bit limited). I thought I'd get some feedback before spending too much time cleaning it up.

What was wrong

Currently it can be a bit fiddly to create fake optional fake data. There are a few projects out there that extend faker to provide this functionality using custom providers, but they're limited in what they can generate. This provides access to everything that would normally be available.

@ligne ligne marked this pull request as ready for review May 26, 2023 20:01
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.

Can you fix the missing type annotation?

@ligne
Copy link
Contributor Author

ligne commented Jun 26, 2023

Sorry for the delay! I was out of the country and it took me a bit of time to catch up with things.

I've taken a slightly roundabout route because i assume you don't really want to have to pull in typing_extensions just for ParamSpec.

I've also fixed it so it the prob parameter is actually honoured!

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.

Thankyou! Could you quickly run make lint against the code?

@ligne
Copy link
Contributor Author

ligne commented Jun 27, 2023

Done! I'd run black, but with the wrong line length. Sorry about that!

faker/proxy.py Outdated Show resolved Hide resolved
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!

@fcurella fcurella merged commit 5fdaaad into joke2k:master Jul 7, 2023
29 checks passed
@PerchunPak
Copy link
Contributor

Haven't you considered also adding a __call__ method for allowing passing custom callable or pure values? Similar to how it's done in my library https://github.com/PerchunPak/optional-faker#example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants