diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 94e13cae38c..f6154ffd889 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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 diff --git a/dask/tests/test_utils.py b/dask/tests/test_utils.py index 3b9aece3c7e..4b4525c338a 100644 --- a/dask/tests/test_utils.py +++ b/dask/tests/test_utils.py @@ -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") diff --git a/dask/utils.py b/dask/utils.py index 6bc9e1f33e8..d5c8d1faa87 100644 --- a/dask/utils.py +++ b/dask/utils.py @@ -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 == "": return "lambda" - return name + return name[:50] except AttributeError: - return str(func) + return str(func)[:50] def typename(typ):