Skip to content

Commit

Permalink
Merge pull request #99 from moskupols/issue-98
Browse files Browse the repository at this point in the history
Match type exactly when checking TYPES_WITH_SAFE_REPR
  • Loading branch information
smarie committed Jul 2, 2024
2 parents c1d189c + 26cc7aa commit 7c95496
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/makefun/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ def _signature_symbol_needs_protection(symbol, evaldict):
:param symbol:
:return:
"""
if symbol is not None and symbol is not Parameter.empty and not isinstance(symbol, TYPES_WITH_SAFE_REPR):
if symbol is not None and symbol is not Parameter.empty and type(symbol) not in TYPES_WITH_SAFE_REPR:
try:
# check if the repr() of the default value is equal to itself.
return eval(repr(symbol), evaldict) != symbol # noqa # we cannot use ast.literal_eval, too restrictive
Expand Down
16 changes: 16 additions & 0 deletions tests/test_issues.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,3 +280,19 @@ def test_issue_91():
"""This test should work also in python 2 ! """
assert is_identifier("_results_bag")
assert is_identifier("hello__bag")


def test_issue_98():
class A(str):
def __str__(self):
return 'custom str'

def __repr__(self):
return 'custom repr'

def foo(a=A()):
pass

@wraps(foo)
def test(*args, **kwargs):
return foo(*args, **kwargs)

0 comments on commit 7c95496

Please sign in to comment.