Skip to content

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

Open
hunterhogan wants to merge 3 commits into
python:mainfrom
hunterhogan:call_normcase
Open

fnmatch calls os.path.normcase(arg)#15963
hunterhogan wants to merge 3 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

Copy link
Copy Markdown
Contributor

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]

@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?

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.

1 participant