Skip to content

[fnmatch] calls os.path.normcase(arg)#15963

Merged
srittau merged 4 commits into
python:mainfrom
hunterhogan:call_normcase
Jun 29, 2026
Merged

[fnmatch] calls os.path.normcase(arg)#15963
srittau merged 4 commits into
python:mainfrom
hunterhogan:call_normcase

Conversation

@hunterhogan

Copy link
Copy Markdown
Contributor

fnmatch.fnmatch, fnmatch.filter, and fnmatch.filterfalse each pass their parameters, name and pat, to os.path.casenorm before operating on the parameters.

if sys.version_info >= (3, 15):
@overload
def normcase(s: PathLike[AnyStr], /) -> AnyStr: ...
@overload
def normcase(s: AnyOrLiteralStr, /) -> AnyOrLiteralStr: ...
else:
@overload
def normcase(s: PathLike[AnyStr]) -> AnyStr: ...
@overload
def normcase(s: AnyOrLiteralStr) -> AnyOrLiteralStr: ...

Therefore, the three fnmatch functions' parameters are AnyOrLiteralStr | PathLike[AnyStr] instead of AnyStr.

If any parameter or parameter's element in filter or filterfalse is PathLike[AnyStr], then the return is limited to list[AnyStr], otherwise it is the superset list[AnyOrLiteralStr].

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@hunterhogan

Copy link
Copy Markdown
Contributor Author

Diff from mypy_primer, showing the effect of this PR on open source code:

setuptools (https://github.com/pypa/setuptools)
+ setuptools/glob.py:106: error: Unused "type: ignore[return-value]" comment  [unused-ignore]

Link to code above.

I feel like this suggests that my proposed type annotations are a step in the right direction because they seem to be more aligned with fnmatch usage "in the wild." Is that a valid interpretation, or am I reading too much into this single hit out of eleventy jillion lines of code?

Comment thread stdlib/fnmatch.pyi Outdated
Comment thread stdlib/fnmatch.pyi Outdated
Comment thread stdlib/fnmatch.pyi Outdated
@github-actions

This comment has been minimized.

@hunterhogan hunterhogan changed the title fnmatch calls os.path.normcase(arg) [fnmatch] calls os.path.normcase(arg) Jun 29, 2026
@github-actions

Copy link
Copy Markdown
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

@srittau srittau left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks!

@srittau srittau merged commit b9090e9 into python:main Jun 29, 2026
58 checks passed
@hunterhogan

Copy link
Copy Markdown
Contributor Author

Thank you for your guidance and patience!

@hunterhogan hunterhogan deleted the call_normcase branch June 29, 2026 14:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants