Skip to content

Add a parameter create to resolve() to create the directory/file if it doesn't exist.#2751

Closed
JackAshwell11 wants to merge 1 commit intopythonarcade:developmentfrom
JackAshwell11:resolve_create
Closed

Add a parameter create to resolve() to create the directory/file if it doesn't exist.#2751
JackAshwell11 wants to merge 1 commit intopythonarcade:developmentfrom
JackAshwell11:resolve_create

Conversation

@JackAshwell11
Copy link
Contributor

No description provided.

Copy link
Collaborator

@DragonMoffon DragonMoffon left a comment

Choose a reason for hiding this comment

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

Looks good otherwise.

Since this PR modifies this code already, could we add an additional check. importlib.resources.Traversable is also a common type passed into this method, and it doesn't have a consistent interface with pathlib.Path. See the docs.

We should either have the function work perfectly with either a Path or Traversable or check for and change a Traversable to a Path

Create a file or directory at the given path.
If the path has a suffix, it's treated as a file, otherwise, as a directory.
"""
if path.suffix:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Path objects have an is_dir method, which is probably a safer check.

Comment on lines +124 to +125
if create:
create_path(path)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should this not also check if the path exists?

@JackAshwell11
Copy link
Contributor Author

Looks good otherwise.

Since this PR modifies this code already, could we add an additional check. importlib.resources.Traversable is also a common type passed into this method, and it doesn't have a consistent interface with pathlib.Path. See the docs.

We should either have the function work perfectly with either a Path or Traversable or check for and change a Traversable to a Path

IIRC, there was a discussion in Discord which deemed that there was a better way to accomplish what I was trying to do with the MR without requiring changes to Arcade. This PR should probably be closed now

@JackAshwell11 JackAshwell11 deleted the resolve_create branch October 18, 2025 16:55
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