Skip to content
Open
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
3 changes: 2 additions & 1 deletion redbaron/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
def baron_type_to_redbaron_classname(baron_type):
return "".join(map(lambda x: x.capitalize(), baron_type.split("_"))) + "Node"


from functools import lru_cache

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Imports should be top level

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

functools.lru_cache is python3 only and will not work in python2. It might be easy to write a cache decorator with no max size:

def memoize(function):
    memo = {}

    @wraps(function)
    def wrapper(*args):
        if args in memo:
            return memo[args]
        else:
            rv = function(*args)
            memo[args] = rv
            return rv
    return wrapper

@lru_cache(maxsize=None)
def redbaron_classname_to_baron_type(name):
name = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', name.replace("Node", ""))
return re.sub('([a-z0-9])([A-Z])', r'\1_\2', name).lower()
Expand Down