Skip to content

Remove typing.AnyStr usage - #5232

Merged
jaraco merged 2 commits into
pypa:mainfrom
sobolevn:remove-AnyStr
Jul 5, 2026
Merged

jaraco merged 2 commits into
pypa:mainfrom
sobolevn:remove-AnyStr

Conversation

@sobolevn

@sobolevn sobolevn commented May 21, 2026 •

Copy link
Copy Markdown
Contributor

Summary of changes

Hi 👋
We are deprecating AnyStr with a warning since Python 3.16, this is a proactive PR to replace it with a modern alternative.
Context python/cpython#150190

Pull Request Checklist

This is not really a user-facing change (at least it should not be), so no changelog entries.

@Avasam

Avasam commented May 27, 2026

Copy link
Copy Markdown
Contributor

Thanks @sobolevn ! Note that any change to the _distutils folder has to be done there: https://github.com/pypa/distutils or it'll get ovewritten next sync

Since this won't be immediately marked as deprecated, I'm tempted to recommend to this project's maintainers to use https://docs.astral.sh/ruff/rules/banned-api/ / https://docs.astral.sh/ruff/settings/#lint_flake8-tidy-imports_banned-api to prevent accidentally adding it back.

@mergify

mergify Bot commented Jun 27, 2026

Copy link
Copy Markdown
Contributor

Tick the box to add this pull request to the merge queue (same as @mergifyio queue).

  • Queue this pull request

…utils.

setuptools/_distutils is vendored from pypa/distutils and is overwritten on
each sync, so the AnyStr change to util.py would be lost (and could conflict
on the next sync). Keeping the setuptools-owned changes (bdist_egg.py, glob.py).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@jaraco

jaraco commented Jul 5, 2026

Copy link
Copy Markdown
Member

Thanks @sobolevn! I pushed a small commit reverting the _distutils/util.py hunk: that tree is vendored from pypa/distutils and is overwritten on each sync, so the change there would be lost (and could conflict on the next sync). It's best made upstream in pypa/distutils. The setuptools-owned changes in bdist_egg.py and glob.py are great — merging those now.

@jaraco
jaraco merged commit 7237672 into pypa:main Jul 5, 2026
0 of 3 checks passed
@jaraco

jaraco commented Jul 5, 2026

Copy link
Copy Markdown
Member

Follow-up: I sent the util.py AnyStr→TypeVar change upstream as pypa/distutils#409 (crediting you as the origin), so it'll persist through the next distutils sync. 🙏

@sobolevn

sobolevn commented Jul 5, 2026

Copy link
Copy Markdown
Contributor Author

@jaraco thank you! Sorry for the late response, it got lost in my notifications :(

jaraco added a commit that referenced this pull request Jul 5, 2026
The AnyStr replacement in #5232 used a bound TypeVar (bound=str | bytes),
but AnyStr is a constrained TypeVar. The stdlib os.path/os.walk/GenericPath
signatures are themselves constrained, so a bound TypeVar (which admits the
str | bytes union) is rejected as an argument. Restore AnyStr's original
semantics with TypeVar(..., str, bytes).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
DimitriPapadopoulos pushed a commit to DimitriPapadopoulos/distutils that referenced this pull request Jul 6, 2026
…hange_root

typing.AnyStr is deprecated (PEP 695 era) and slated for removal. Use an
explicit TypeVar constrained to (str, bytes) to preserve the same typing
behavior for change_root.

Originally proposed by @sobolevn in pypa/setuptools#5232, where distutils is
vendored; making the change here so it persists through the next sync.

Co-Authored-By: sobolevn <46602750+sobolevn@users.noreply.github.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.

4 participants