Skip to content

Commit 07427f8

Browse files
authored
Fix routing.get_name() not to assume all routines have __name__ (#2648)
Fix `routing.get_name()` to use the `__name__` attribute only if it is actually present, rather than assuming that all routine and class types have it, and use the fallback to class name otherwise. This is necessary for `functools.partial()` that doesn't have a `__name__` attribute, but is recognized as a routine starting with Python 3.13.0b3. Since for older versions of Python, it would have used the fallback anyway, this doesn't really change the behavior there. Fixes #2638
1 parent 921f137 commit 07427f8

File tree

1 file changed

+1
-3
lines changed

1 file changed

+1
-3
lines changed

starlette/routing.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,7 @@ async def app(scope: Scope, receive: Receive, send: Send) -> None:
9999

100100

101101
def get_name(endpoint: typing.Callable[..., typing.Any]) -> str:
102-
if inspect.isroutine(endpoint) or inspect.isclass(endpoint):
103-
return endpoint.__name__
104-
return endpoint.__class__.__name__
102+
return getattr(endpoint, "__name__", endpoint.__class__.__name__)
105103

106104

107105
def replace_params(

0 commit comments

Comments
 (0)