Skip to content

Commit

Permalink
Truncate funcname to avoid long key names
Browse files Browse the repository at this point in the history
  • Loading branch information
mrocklin committed Sep 9, 2019
1 parent 96bbf63 commit 3d7b568
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ repos:
- id: black
language_version: python3.7
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.2.3
rev: v2.3.0
hooks:
- id: flake8
11 changes: 11 additions & 0 deletions dask/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,17 @@ class Foo(object):
assert "Foo" in funcname(Foo())


def test_funcname_long():
def a_long_function_name_11111111111111111111111111111111111111111111111():
pass

result = funcname(
a_long_function_name_11111111111111111111111111111111111111111111111
)
assert "a_long_function_name" in result
assert len(result) < 60


def test_funcname_toolz():
toolz = pytest.importorskip("toolz")

Expand Down
10 changes: 5 additions & 5 deletions dask/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -675,26 +675,26 @@ def funcname(func):
return funcname(func.func)
# methodcaller
if isinstance(func, methodcaller):
return func.method
return func.method[:50]

module_name = getattr(func, "__module__", None) or ""
type_name = getattr(type(func), "__name__", None) or ""

# toolz.curry
if "toolz" in module_name and "curry" == type_name:
return func.func_name
return func.func_name[:50]
# multipledispatch objects
if "multipledispatch" in module_name and "Dispatcher" == type_name:
return func.name
return func.name[:50]

# All other callables
try:
name = func.__name__
if name == "<lambda>":
return "lambda"
return name
return name[:50]
except AttributeError:
return str(func)
return str(func)[:50]


def typename(typ):
Expand Down

0 comments on commit 3d7b568

Please sign in to comment.