-
Notifications
You must be signed in to change notification settings - Fork 17
Closed
Description
This issue is similar to #63
from enum import StrEnum
from makefun import wraps
class A(StrEnum):
a = 'a'
def foo(a=A.a):
pass
@wraps(foo)
def test(*args, **kwargs):
return foo(*args, **kwargs)
When this runs it throws:
Error in generated code:
def foo(a=<A.a: 'a'>):
return _func_impl_(a=a)
Traceback (most recent call last):
File "/home/alexeyd/a.py", line 10, in <module>
@wraps(foo)
^^^^^^^^^^
File "/usr/python3.11/lib/python3.11/site-packages/makefun/main.py", line 1062, in replace_f
return create_function(func_signature=func_signature,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/python3.11/lib/python3.11/site-packages/makefun/main.py", line 323, in create_function
f = _make(co_name, params_names, body, evaldict)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/python3.11/lib/python3.11/site-packages/makefun/main.py", line 714, in _make
code = compile(body, filename, 'single')
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<makefun-gen-0>", line 1
def foo(a=<A.a: 'a'>):
^
SyntaxError: invalid syntax
The problem is StrEnum is also an str (that's a point of the class), so here it is assumed to have safe repr.
I propose to change the check from checking isinstance to checking type(symbol) in TYPES_WITH_SAFE_REPR
neprune
Metadata
Metadata
Assignees
Labels
No labels