Skip to content

Fix WindowsPath subclass construction on Python 3.12+ - #238

Closed
9Kun wants to merge 1 commit into
facelessuser:mainfrom
9Kun:fix/windows-path-subclasses
Closed

9Kun wants to merge 1 commit into
facelessuser:mainfrom
9Kun:fix/windows-path-subclasses

Conversation

@9Kun

@9Kun 9Kun commented Sep 29, 2026

Copy link
Copy Markdown

Summary

Fix construction of WindowsPath subclasses on Windows with Python 3.12+.
The platform check compares the class identity with WindowsPath, so a subclass
is treated as a non-Windows path and rejected before it can be used.

Reproduced on Windows with Python 3.12.14 and 3.14.0 (upstream
9f8a9f6b7479e8ee4d033976d0a24faaca4a1830, wcmatch 11.0.1):

from wcmatch.pathlib import WindowsPath

class ProjectPath(WindowsPath):
    pass

ProjectPath('example.txt')
# NotImplementedError: Cannot instantiate 'ProjectPath' on your system

The equivalent standard-library subclass can be instantiated on Windows. This
prevents applications from extending the concrete path class with their own
helpers while retaining wcmatch's glob methods.

Use issubclass for the existing platform check. This also keeps Windows-derived
concrete paths from being instantiated on non-Windows hosts. The pre-3.12 branch,
exception type, and matching implementation are unchanged.

Four regression/control cases cover direct and indirect subclasses of both
concrete path classes. On the native platform they check construction, joining,
file access, matching, glob/rglob, and preservation of the subclass in returned
paths; the other platform's concrete subclasses must still be rejected.

Validation

  • New cases against the unchanged implementation on Windows/Python 3.14:
    2 failed, 2 passed. The failures are the direct and indirect Windows subclasses.
  • Full suite on Windows/Python 3.14.0: 1247 passed, 166 skipped, with 97% overall
    statement/branch coverage reported by coverage.py.
  • Full suite on Windows/Python 3.12.14: 1247 passed, 166 skipped.
  • python -m mypy: passes on both tested interpreters.
  • python -m ruff check .: passes, including the configured style checks.
  • python -m build: sdist and wheel-from-sdist builds pass in isolated build environments.
  • A separately installed wheel passes an isolated-import smoke test for subclass
    construction, joining, file access, matching, and glob/rglob.
  • python -m pip check and git diff --check: pass.

The 166 skips also occur on the unchanged baseline and reflect existing
platform/option conditions, unavailable symlink support and dir_fd support.
Linux/macOS and the remaining supported Python versions were not run locally.
Documentation/spelling checks were not run; no documentation was changed.

AI assistance

This contribution was found through source inspection and local reproduction,
not a reported production incident. OpenAI Codex (GPT-6 Astra), acting with the
submitting account owner's authorization, selected the issue, wrote the patch
and tests, ran the checks above, reviewed the diff, and prepared this PR. No
independent human review is claimed. No matching issue or existing fix was found
in the issue/PR searches, so no separate issue was opened.

@gir-bot gir-bot added S: needs-review Needs to be reviewed and/or approved. C: pathlib Pathlib library. C: source Related to source code. C: tests Related to testing. labels Sep 29, 2026

@facelessuser facelessuser left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

This is a good find. Please make the requested adjustment so we can merge this in.

Comment thread tests/test_pathlib.py
@pytest.mark.parametrize('base', [pathlib.WindowsPath, pathlib.PosixPath])
@pytest.mark.parametrize('depth', [1, 2])
def test_subclass(self, base, depth, tmp_path):
"""Keep platform restrictions and glob functionality when subclassing paths."""

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Please add "subclassing" to en-custom.txt to avoid having it cause the spell checker to fail.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

@9Kun in case you missed it, we are just needing one change in order to get this merged. We would love to get this in the next release.

@facelessuser

Copy link
Copy Markdown
Owner

@9Kun We are going to manually merge this PR this time, but if you plan to contribute in the future, we require contributors to be available for follow-up questions and revisions if providing a PR.

Be prepared to answer questions and provide additional information if required. Issues in which the creator refuses to respond to follow up questions will be marked as stale and closed.

@facelessuser

Copy link
Copy Markdown
Owner

@9Kun We are going to manually merge this PR this time, but if you plan to contribute in the future, we require contributors to be available for follow-up questions and revisions when submitting a PR.

As noted in our documentation:

Be prepared to answer questions and provide additional information if required. Issues in which the creator refuses to respond to follow-up questions will be marked as stale and closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C: pathlib Pathlib library. C: source Related to source code. C: tests Related to testing. S: needs-review Needs to be reviewed and/or approved.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants