From: Michał Górny Date: Wed, 24 Jul 2024 08:23:59 +0000 (+0200) Subject: Fix `routing.get_name()` not to assume all routines have `__name__` (#2648) X-Git-Tag: 0.38.2~3 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=07427f86474b15d648497014eb19c41f01317f15;p=thirdparty%2Fstarlette.git 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 --- diff --git a/starlette/routing.py b/starlette/routing.py index 75a5ec3f..481b13f5 100644 --- a/starlette/routing.py +++ b/starlette/routing.py @@ -99,9 +99,7 @@ def websocket_session( def get_name(endpoint: typing.Callable[..., typing.Any]) -> str: - if inspect.isroutine(endpoint) or inspect.isclass(endpoint): - return endpoint.__name__ - return endpoint.__class__.__name__ + return getattr(endpoint, "__name__", endpoint.__class__.__name__) def replace_params(