Skip to content

Commit

Permalink
Fixed get_callable_name() not working properly for built-in functions
Browse files Browse the repository at this point in the history
  • Loading branch information
agronholm committed Aug 12, 2023
1 parent 98212e2 commit f2ccf7d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
4 changes: 2 additions & 2 deletions apscheduler/util.py
Expand Up @@ -6,7 +6,7 @@
from datetime import date, datetime, time, timedelta, tzinfo
from calendar import timegm
from functools import partial
from inspect import isclass, isfunction, ismethod
from inspect import isbuiltin, isclass, isfunction, ismethod
import re
import sys

Expand Down Expand Up @@ -218,7 +218,7 @@ def get_callable_name(func):
self = func.__self__
cls = self if isclass(self) else type(self)
return f"{cls.__qualname__}.{func.__name__}"
elif isclass(func) or isfunction(func):
elif isclass(func) or isfunction(func) or isbuiltin(func):
return func.__qualname__
elif hasattr(func, '__call__') and callable(func.__call__):
# instance of a class with a __call__ method
Expand Down
8 changes: 5 additions & 3 deletions tests/test_util.py
@@ -1,3 +1,4 @@
import os
import platform
import sys
from datetime import date, datetime, timedelta, tzinfo
Expand Down Expand Up @@ -176,16 +177,17 @@ def test_datetime_repr(input, expected):
class TestGetCallableName(object):
@pytest.mark.parametrize('input,expected', [
(asint, 'asint'),
(os.getpid, "getpid"),
(DummyClass.staticmeth, 'DummyClass.staticmeth'),
(DummyClass.classmeth, 'DummyClass.classmeth'),
(DummyClass.meth, 'DummyClass.meth'),
(DummyClass().meth, 'DummyClass.meth'),
(DummyClass, 'DummyClass'),
(DummyClass(), 'DummyClass'),
(InheritedDummyClass.classmeth, "InheritedDummyClass.classmeth"),
(DummyClass.InnerDummyClass.innerclassmeth, "DummyClass.InnerDummyClass.innerclassmeth")
], ids=['function', 'static method', 'class method', 'unbounded method', 'bounded method',
'class', 'instance', "class method in inherited", "inner class method"])
(DummyClass.InnerDummyClass.innerclassmeth, "DummyClass.InnerDummyClass.innerclassmeth"),
], ids=['function', 'builtin', 'static method', 'class method', 'unbounded method',
'bounded method', 'class', 'instance', "class method in inherited", "inner class method"])
def test_inputs(self, input, expected):
assert get_callable_name(input) == expected

Expand Down

0 comments on commit f2ccf7d

Please sign in to comment.