Skip to content

NameError: name 'inf' is not defined #63

Closed

Description

@zqbake

When the source function has a parameter with a default value float('inf')
The @with_signature decorator raises this error.

A minor example:

def a(a = float("inf")):
    pass
import inspect
from makefun import with_signature
@with_signature(inspect.signature(a))
def test(*args, **kwargs):
    return a(*args, **kwargs)

Activity

  1. smarie commented on Mar 16, 2021

    @smarie
    Owner

    Thanks for the feedback @zhqu1148980644 ! This can also be reproduced using @wraps :

    def foo(a=float("inf")):
        pass
    
    @wraps(foo)
    def test(*args, **kwargs):
        return foo(*args, **kwargs)

    Being able to compile functions dynamically with non-primitive default values is tricky. It is currently being done in get_signature_string. If a non-primitive symbol is seen in the default values it is added to the eval dict. Maybe there is something in your example that does not work with this mechanism, I'll have a look.

  2. smarie commented on Mar 16, 2021

    @smarie
    Owner

    Oh I see, I was assuming that all int, str, float, bool have a repr that is directly understandable by the compiler. However this is not the case for inf, -inf and nan.

    I remove float from the types that are assumed safe. I take this opportunity to add bytes to the ones that are assumed safe.

  3. smarie commented on Mar 16, 2021

    @smarie
    Owner

    Fixed in 1.11.1, let me know if the fix works for you !

  4. zqbake commented on Mar 16, 2021

    @zqbake
    Author

    Thanks, it worked.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions