Skip to content

Commit 3975a83

Browse files
committed
WIP
1 parent 8c437f2 commit 3975a83

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

typemap/type_eval/_apply_generic.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,15 @@ def get_local_defns(boxed: Boxed) -> tuple[dict[str, Any], dict[str, Any]]:
248248
annos: dict[str, Any] = {}
249249
dct: dict[str, Any] = {}
250250

251-
if (rr := get_annotations(boxed.cls, boxed.str_args)) is not None:
251+
# Include the class itself in args so that self-referential string
252+
# annotations (e.g. from `from __future__ import annotations`) in
253+
# nested scopes can be resolved during eval. (This only half
254+
# solves that general problem, but it is the best we can do.)
255+
str_args = boxed.str_args
256+
if boxed.cls.__name__ not in str_args:
257+
str_args = {**str_args, boxed.cls.__name__: boxed.cls}
258+
259+
if (rr := get_annotations(boxed.cls, str_args)) is not None:
252260
annos.update(rr)
253261

254262
for name, orig in boxed.cls.__dict__.items():
@@ -264,7 +272,7 @@ def get_local_defns(boxed: Boxed) -> tuple[dict[str, Any], dict[str, Any]]:
264272
# __annotations__ on methods broke stuff and I didn't want
265273
# to chase it down yet.
266274
if (
267-
rr := get_annotations(stuff, boxed.str_args, annos_ok=False)
275+
rr := get_annotations(stuff, str_args, annos_ok=False)
268276
) is not None:
269277
local_fn = make_func(orig, rr)
270278
elif getattr(stuff, "__annotations__", None):

0 commit comments

Comments
 (0)