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

Allow extension in file_path to take a list of allowed extensions, or empty for "no extension" #1966

Merged
merged 4 commits into from
Dec 29, 2023

Conversation

gotofritz
Copy link
Contributor

@gotofritz gotofritz commented Dec 20, 2023

What does this change

Change to file_path behaviour: allow extension to take a list of allowed extensions, or empty for "no extension". Non-breaking change.

What was wrong

There was no way to have a path without extension

How this fixes it

As proposed by @joke2k, passing a list allows to have no extension is list is empty, but it also allows the user to provide a list of candidate extensions from which to pick one.

Fixes #1964

"""
no_extension = False
if isinstance(extension, list):
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd like for extension to also possibly a tuple.
We could type the argument with extension: Optional[Sequence[str]], and then check for not isinstance(extension, str) instead:

Suggested change
if isinstance(extension, list):
if not isinstance(extension, str):

I would also change the behavior of file_name, so that if the empty string is passed, no extension and no dot are added. This would allow us to pass "" to file_name and avoid stripping it out later.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done - also checking for None

faker/providers/file/__init__.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 58f49e0 into joke2k:master Dec 29, 2023
28 checks passed
@gotofritz gotofritz deleted the fix/master/1964_paths branch December 29, 2023 23:50
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.

Feature request: file_path extension=False to generate a path without extension
2 participants