Coder Social home page Coder Social logo

Comments (7)

zhukoff-pavel avatar zhukoff-pavel commented on June 24, 2024 1

Recursive expansion isn't supported, and so ** wildcards work exactly like *

Oh, I see. So, this is intended. Thank you for quick reply!

Is it possible then to add this note to the documentation of previous Python versions? (e.g. Python 3.12)

By the way, side-question regarding naming: Doesn't full_match sound more strict than just match? :)
full_match seems more relaxed than the regular match, because of allowing for recursive patterns to be used, thus allowing more matches per recursive glob.

from cpython.

barneygale avatar barneygale commented on June 24, 2024 1

By the way, side-question regarding naming: Doesn't full_match sound more strict than just match? :) full_match seems more relaxed than the regular match, because of allowing for recursive patterns to be used, thus allowing more matches per recursive glob.

full_match() matches against the entire path, whereas match() matches from the right, so:

>>> from pathlib import PurePath
>>> PurePath('foo/bar.py').match('*.py')
True
>>> PurePath('foo/bar.py').full_match('*.py')
False

It's analogous to re.match() vs re.fullmatch().

Support for recursive ** wildcards only really makes sense once you eliminate the right-hand-side matching, otherwise all your patterns have an implicit **/ prefix, which makes it much less useful.

from cpython.

barneygale avatar barneygale commented on June 24, 2024 1

No worries, thank you very much for the report :)

from cpython.

zhukoff-pavel avatar zhukoff-pavel commented on June 24, 2024

Follow-up: May be connected with #106747

from cpython.

sobolevn avatar sobolevn commented on June 24, 2024

cc @barneygale

from cpython.

barneygale avatar barneygale commented on June 24, 2024

PurePath.match() has a couple of important differences from Path.glob() and glob.glob():

  1. Recursive expansion isn't supported, and so ** wildcards work exactly like *
  2. If a relative pattern is given, matching is performed from the right

Could you try using Path.full_match() in an alpha or (upcoming) beta of 3.13? I think it does what you want:

>>> import pathlib
>>> path = pathlib.PurePath("a/b/c/d/e")
>>> path.full_match("**/b/c/**")
True
>>> path.full_match("**/c/d/**")
True

from cpython.

zhukoff-pavel avatar zhukoff-pavel commented on June 24, 2024

I see now.

Thank you for detailed explanations and for documenting!

from cpython.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.