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

⚡️ Speed up method Path.coerce_path_result by 6% #35

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions src/click/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -857,15 +857,13 @@ def to_info_dict(self) -> dict[str, t.Any]:
def coerce_path_result(
self, value: str | os.PathLike[str]
) -> str | bytes | os.PathLike[str]:
if self.type is not None and not isinstance(value, self.type):
if self.type is str:
return os.fsdecode(value)
elif self.type is bytes:
return os.fsencode(value)
else:
return t.cast("os.PathLike[str]", self.type(value))

return value
if self.type is None or isinstance(value, self.type):
return value
if self.type is str:
return os.fsdecode(value)
if self.type is bytes:
return os.fsencode(value)
return t.cast("os.PathLike[str]", self.type(value))

def convert(
self,
Expand Down