Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Match type exactly when checking TYPES_WITH_SAFE_REPR #99

Merged
merged 3 commits into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)