Skip to content

Commit 1e04277

Browse files
committed
address 3.13 deprecations
1 parent 4df24f0 commit 1e04277

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

basedtyping/__init__.py

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@
4444

4545

4646
if not TYPE_CHECKING:
47-
if sys.version_info >= (3, 11):
47+
if sys.version_info >= (3, 13):
48+
from typing import _collect_type_parameters as _collect_parameters
49+
elif sys.version_info >= (3, 11):
4850
from typing import _collect_parameters
4951
else:
5052
from typing import _collect_type_vars as _collect_parameters
@@ -809,13 +811,17 @@ class A(Base):
809811
if value is None: # type: ignore[no-any-expr]
810812
value = type(None)
811813
if isinstance(value, str): # type: ignore[no-any-expr]
812-
if sys.version_info < (3, 9):
813-
value = ForwardRef(value, is_argument=False)
814-
else:
815-
value = ForwardRef(value, is_argument=False, is_class=True)
816-
value = typing._eval_type(value, base_globals, base_locals, recursive_guard=1) # type: ignore[attr-defined, no-any-expr]
814+
value = ForwardRef(value, is_argument=False, is_class=True)
815+
if sys.version_info < (3, 12):
816+
value = typing._eval_type(value, base_globals, base_locals) # type: ignore[attr-defined, no-any-expr]
817+
else:
818+
value = typing._eval_type( # type: ignore[attr-defined]
819+
value, # type: ignore[no-any-expr]
820+
base_globals, # type: ignore[no-any-expr]
821+
base_locals, # type: ignore[no-any-expr]
822+
base.__type_params__,
823+
)
817824
hints[name] = value # type: ignore[no-any-expr]
818-
819825
return hints if include_extras else {k: _strip_annotations(t) for k, t in hints.items()} # type: ignore[no-any-expr]
820826

821827
if globalns is None:
@@ -836,8 +842,9 @@ class A(Base):
836842
# Return empty annotations for something that _could_ have them.
837843
if isinstance(obj, typing._allowed_types): # type: ignore[ unreachable]
838844
return {}
839-
raise TypeError(f"{obj!r} is not a module, class, method, " "or function.")
845+
raise TypeError(f"{obj!r} is not a module, class, method, or function.")
840846
hints = dict(hints) # type: ignore[no-any-expr]
847+
type_params = getattr(obj, "__type_params__", ()) # type: ignore[no-any-expr]
841848
for name, value in hints.items(): # type: ignore[no-any-expr]
842849
if value is None: # type: ignore[no-any-expr]
843850
value = type(None)
@@ -849,5 +856,8 @@ class A(Base):
849856
is_argument=not isinstance(cast(object, obj), types.ModuleType),
850857
is_class=False,
851858
)
852-
hints[name] = typing._eval_type(value, globalns, localns) # type: ignore[no-any-expr, attr-defined]
859+
if sys.version_info >= (3, 12):
860+
hints[name] = typing._eval_type(value, globalns, localns, type_params=type_params) # type: ignore[no-any-expr, attr-defined]
861+
else:
862+
hints[name] = typing._eval_type(value, globalns, localns) # type: ignore[no-any-expr, attr-defined]
853863
return hints if include_extras else {k: _strip_annotations(t) for k, t in hints.items()} # type: ignore[no-any-expr]

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ always_false = ["BASEDMYPY_TYPE_CHECKING"]
3232
skip-magic-trailing-comma = true
3333

3434
[tool.pytest.ini_options]
35-
addopts = "--import-mode=importlib"
35+
filterwarnings = "error"
3636
xfail_strict = true
3737

3838
[tool.ruff]

0 commit comments

Comments
 (0)