Content-Length: 281825 | pFad | https://github.com/python/cpython/issues/126363

ad Speed up pattern parsing in `pathlib.Path.glob()` · Issue #126363 · python/cpython · GitHub
Skip to content

Speed up pattern parsing in pathlib.Path.glob() #126363

Description

@barneygale

pathlib.Path.glob() converts a given string pattern to a Path object:

if not isinstance(pattern, PurePath):
pattern = self.with_segments(pattern)

Which has the following drawbacks:

  • It instantiates a Path object, which is slow
  • It normalizes a Windows UNC drive if given, which is unnecessary - any anchor causes NotImplementedError to be raised.
  • It strips the trailing slash from the pattern, so we need to peek at pattern._raw_path to restore it

It would be better to add a variant of PurePath._parse_path() for dealing specifically with glob patterns.

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions









    ApplySandwichStrip

    pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


    --- a PPN by Garber Painting Akron. With Image Size Reduction included!

    Fetched URL: https://github.com/python/cpython/issues/126363

    Alternative Proxies:

    Alternative Proxy

    pFad Proxy

    pFad v3 Proxy

    pFad v4 Proxy