Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Remove redundant type check inos.path.join() #117636

Closed
Labels
performancePerformance or resource usagestdlibStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancement
@nineteendo

Description

@nineteendo

Feature or enhancement

Proposal:

These type checks were introduced a long time ago in5bfc03f and became redundant in3f9183b with the addition ofos.fspath(). They can be safely removed, slightly speeding upos.path.join() in the process:

 def join(path, *paths):     path = os.fspath(path)     if isinstance(path, bytes):         sep = b'\\'         seps = b'\\/'         colon_seps = b':\\/'     else:         sep = '\\'         seps = '\\/'         colon_seps = ':\\/'     try:-        if not paths:-            path[:0] + sep  #23780: Ensure compatible data type even if p is null.
 def join(a, *p):     """Join two or more pathname components, inserting '/' as needed.     If any component is an absolute path, all previous path components     will be discarded.  An empty last part will result in a path that     ends with a separator."""     a = os.fspath(a)     sep = _get_sep(a)     path = a     try:-        if not p:-            path[:0] + sep  #23780: Ensure compatible data type even if p is null.

I also noticed we're concatenatingb to an empty string inposixpath.join() in casepath has a length of 0. Which we can fix quite easily:

-if b.startswith(sep):+if b.startswith(sep) or not path:     path = b-elif not path or path.endswith(sep):+elif path.endswith(sep):     path += b

Has this already been discussed elsewhere?

This is a minor feature, which does not need previous discussion elsewhere

Links to previous discussion of this feature:

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    performancePerformance or resource usagestdlibStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancement

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp