python-attrs / cattrs

Composable custom class converters for attrs, dataclasses and friends.
https://catt.rs
MIT License
779 stars 108 forks source link

Make detection of TypeVar defaults robust to the CPython PEP-696 implementation #536

Closed AlexWaygood closed 1 month ago

AlexWaygood commented 1 month ago

When implementing PEP 696 (default values for TypeVars, ParamSpecs and TypeVarTuples, we decided to implement the PEP slightly differently from the prototype that existed in typing_extensions. Specifically:

I backported these changes to the typing_extensions implementation of PEP 696 yesterday, and we realised today that it breaks some tests over at cattrs: https://github.com/python/typing_extensions/issues/381. This PR fixes the tests so that they work if you're using a released version of typing_extensions, but they also work with the CPython implementation of PEP 696 and with the typing_extensions main branch.

I tested the PR locally by making this change to pyproject.toml:

--- a/pyproject.toml
+++ b/pyproject.toml
@@ -43,7 +43,7 @@ authors = [
 ]
 dependencies = [
     "attrs>=23.1.0",
-    "typing-extensions>=4.1.0, !=4.6.3; python_version < '3.11'",
+    "typing-extensions @ git+https://github.com/python/typing_extensions.git",
     "exceptiongroup>=1.1.1; python_version < '3.11'",
 ]
 requires-python = ">=3.8"
@@ -148,6 +148,9 @@ ignore = [
     "DTZ006", # datetimes in tests
 ]

+[tool.hatch.metadata]
+allow-direct-references = true
+
 [tool.hatch.version]

And then re-running pdm install -d -G :all and tox. The tests all passed.

I didn't add an entry to HISTORY.md, as it looks like cattrs's PEP-696 support is unreleased right now (so it's a bugfix for an unreleased feature)!

Tinche commented 1 month ago

Nice, thanks a lot!