Skip to content

Commit 9d7a00f

Browse files
authored
Fix breakage because we produce unhashable staticmethod/classmethod (#18)
Fix it for now by wrapping the list in a tuple[]. I need to think about what is actually right here.
1 parent b5f8cb4 commit 9d7a00f

3 files changed

Lines changed: 7 additions & 5 deletions

File tree

tests/test_type_dir.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ def test_type_members_func_2():
346346
assert (
347347
str(typ)
348348
== "\
349-
classmethod[tests.test_type_dir.Final, [typemap.typing.Param[typing.Literal['a'], int | None, typing.Never], typemap.typing.Param[typing.Literal['b'], ~K, typing.Never]], dict[str, int]]"
349+
classmethod[tests.test_type_dir.Final, tuple[typemap.typing.Param[typing.Literal['a'], int | None, typing.Never], typemap.typing.Param[typing.Literal['b'], ~K, typing.Never]], dict[str, int]]"
350350
)
351351

352352

@@ -361,5 +361,5 @@ def test_type_members_func_3():
361361
assert (
362362
str(typ)
363363
== "\
364-
staticmethod[[typemap.typing.Param[typing.Literal['a'], int | typing.Literal['gotcha!'] | Z | None, typing.Never], typemap.typing.Param[typing.Literal['b'], ~K, typing.Never]], dict[str, int | Z]]"
364+
staticmethod[tuple[typemap.typing.Param[typing.Literal['a'], int | typing.Literal['gotcha!'] | Z | None, typing.Never], typemap.typing.Param[typing.Literal['b'], ~K, typing.Never]], dict[str, int | Z]]"
365365
)

typemap/type_eval/_eval_operators.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,10 +229,12 @@ def _ann(x):
229229

230230
ret = _ann(sig.return_annotation)
231231

232+
# TODO: Is doing the tuple for staticmethod/classmethod legit?
233+
# Putting a list in makes it unhashable...
232234
if isinstance(func, staticmethod):
233-
return staticmethod[params, ret]
235+
return staticmethod[tuple[*params], ret]
234236
elif isinstance(func, classmethod):
235-
return classmethod[specified_receiver, params[1:], ret]
237+
return classmethod[specified_receiver, tuple[*params[1:]], ret]
236238
else:
237239
return typing.Callable[params, ret]
238240

typemap/type_eval/_eval_typing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ def _child_context() -> typing.Iterator[EvalContext]:
174174
def eval_typing(obj: typing.Any):
175175
with _ensure_context() as ctx:
176176
result = _eval_types(obj, ctx)
177-
if result in ctx.known_recursive_types:
177+
if not isinstance(result, list) and result in ctx.known_recursive_types:
178178
result = ctx.known_recursive_types[result]
179179
return result
180180

0 commit comments

Comments
 (0)