Skip to content

gh-105578: Raise DeprecationWarning on typing.AnyStr usage - #150190

Merged
sobolevn merged 9 commits into
python:mainfrom
sobolevn:issue-105578
Nov 5, 2026
Merged

sobolevn merged 9 commits into
python:mainfrom
sobolevn:issue-105578

Conversation

@sobolevn

@sobolevn sobolevn commented May 21, 2026 •

Copy link
Copy Markdown
Member

@read-the-docs-community

read-the-docs-community Bot commented May 21, 2026 •

Copy link
Copy Markdown

@AlexWaygood AlexWaygood left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks! Wow, that came around quickly.

I had to think this through again, but I think this is correct: this is a deprecation for Python 3.16, which will become stable in autumn 2027, around the same time that Python 3.11 goes end-of-life. That means that the deprecation warnings will start to be emitted at basically the same time that the lowest non-EOL Python version is Python 3.12 -- and Python 3.12 is the first version in which users can use PEP-695 syntax

Comment thread Doc/library/typing.rst Resolved
Comment thread Lib/typing.py Resolved
Comment thread Lib/typing.py Resolved
@AlexWaygood

Copy link
Copy Markdown
Member

the test failures from the deprecation warnings in setuptools in https://github.com/python/cpython/actions/runs/26230364757/job/77188896358?pr=150190 do seem a bit concerning. Do we need to update setuptools before landing this?

@github-actions

Copy link
Copy Markdown

This PR is stale because it has been open for 90 days with no activity.

@github-actions github-actions Bot added the stale Stale PR or inactive for long period of time. label Aug 19, 2026
@bedevere-app bedevere-app Bot added the type-feature A feature request or enhancement label Oct 28, 2026
@sobolevn

sobolevn commented Oct 28, 2026 •

Copy link
Copy Markdown
Member Author

Setuptools is updated, new version is released. I've fixed all merge conflicts.

Comment thread Lib/typing.py Resolved
@sobolevn sobolevn removed the stale Stale PR or inactive for long period of time. label Oct 28, 2026
Comment thread Lib/test/test_typing.py Resolved
@sobolevn

Copy link
Copy Markdown
Member Author

We can address the setuptools.whl tests failures in two ways:

  1. We can update the bundled .whl to a newer version
  2. Or we can add warnings ignore guards

I think that both have their downsides, but I would probably go with 1 :)

Comment thread Lib/typing.py Resolved
Comment thread Lib/typing.py Resolved
Comment thread Lib/typing.py Resolved
sobolevn and others added 2 commits October 28, 2026 14:51
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
@sobolevn

Copy link
Copy Markdown
Member Author

I created #160824 to discuss the setuptools update.

@sobolevn

sobolevn commented Nov 5, 2026

Copy link
Copy Markdown
Member Author

I fixed setuptools, updated the bundled wheel file, now tests should pass (finally 🎉)!

Please, take another look :)

Comment thread Doc/whatsnew/3.16.rst Resolved
@sobolevn
sobolevn enabled auto-merge (squash) November 5, 2026 21:34
@sobolevn

sobolevn commented Nov 5, 2026

Copy link
Copy Markdown
Member Author

Thanks a lot, everyone! 🎉

@sobolevn
sobolevn merged commit d746542 into python:main Nov 5, 2026
53 checks passed
@hugovk

hugovk commented Nov 6, 2026

Copy link
Copy Markdown
Member

Looks like this has caused buildbot refleak failures:

https://buildbot.python.org/release-status

For example:

The other test that does import_helper.import_fresh_module('typing') has self.addCleanup(atexit.unregister, typing._clear_caches).

def test_collect_parameters(self):
typing = import_helper.import_fresh_module("typing")
# Importing typing registers an internal function named _clear_caches
# with atexit. The throwaway module created here installs its own
# handler, which holds the module alive and keeps references until
# interpreter shutdown even after the test finishes. Each repetition
# of this test under -R would therefore leak another module copy. To
# avoid this, we unregister the handler once the test is done.
self.addCleanup(atexit.unregister, typing._clear_caches)
with self.assertWarnsRegex(
DeprecationWarning,
"The private _collect_parameters function is deprecated"
) as cm:
typing._collect_parameters
self.assertEqual(cm.filename, __file__)

Do we need similar in test_any_str_deprecated?

@sobolevn

sobolevn commented Nov 6, 2026

Copy link
Copy Markdown
Member Author

Oups, sorry for that! Fixing :)

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

Labels

type-feature A feature request or enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants