Skip to content

can't require a function named f #5698

@porterjamesj

Description

@porterjamesj

It took me a while to figure this one out:

def f(x):
    return(x)

@require(f):
def g(y):
    return f(y)

gives:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-86-98a37b0c736a> in <module>()
----> 1 @require(f)
      2 def g(y):
      3     return f(y)
      4

/usr/local/lib/python2.7/dist-packages/IPython/parallel/controller/dependency.pyc in require(*objects, **mapping)
    133     for name, obj in mapping.items():
    134         mapping[name] = can(obj)
--> 135     return depend(_require, *names, **mapping)
    136
    137 class Dependency(set):

TypeError: __init__() got multiple values for keyword argument 'f'

I believe the cause is the use of f as a name in the constructor here.

This seems like a bit of an arbitrary restriction; it may not be possible to get around having to forbid the use of some function name, but at least we could maybe use something less likely to collide with users' things (_f maybe?).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions