Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python 3.13.0b3: AttributeError: 'functools.partial' object has no attribute '__name__' #2638

Closed
1 task done
musicinmybrain opened this issue Jul 6, 2024 · 1 comment · Fixed by #2648
Closed
1 task done

Comments

@musicinmybrain
Copy link
Contributor

musicinmybrain commented Jul 6, 2024

$ gh repo clone encode/starlette
$ cd starlette
$ python3.13 --version
Python 3.13.0b3
$ python3.13 -m venv _e
$ . _e/bin/activate
(_e) $ pip install -r requirements.txt
(_e) $ pip install -e .
(_e) $ python -m pytest
_e/lib64/python3.13/site-packages/trio/_path.py:164: in generate_forwards
    raise TypeError(attr_name, type(attr))
E   TypeError: ('parser', <class 'module'>)
(_e) $ pip install --upgrade trio
(_e) $ python -m pytest
==================================================================================================== ERRORS ====================================================================================================
____________________________________________________________________________________ ERROR collecting tests/test_routing.py ____________________________________________________________________________________
tests/test_routing.py:135: in <module>
    Route("/", endpoint=functools.partial(partial_endpoint, "foo")),
starlette/routing.py:227: in __init__
    self.name = get_name(endpoint) if name is None else name
starlette/routing.py:103: in get_name
    return endpoint.__name__
E   AttributeError: 'functools.partial' object has no attribute '__name__'. Did you mean: '__ne__'?
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
=============================================================================================== 1 error in 0.64s ===============================================================================================

This appears to be a new regression in Python 3.13.0b3 (vs. 3.13.0b2).


Important

  • We're using Polar.sh so you can upvote and help fund this issue.
  • We receive the funding once the issue is completed & confirmed by you.
  • Thank you in advance for helping prioritize & fund our backlog.
Fund with Polar
@mgorny
Copy link
Contributor

mgorny commented Jul 21, 2024

This is according to the documentation:

partial objects are like function objects in that they are callable, weak referenceable, and can have attributes. There are some important differences. For instance, the name and doc attributes are not created automatically.

https://docs.python.org/3/library/functools.html#partial-objects

mgorny added a commit to mgorny/starlette that referenced this issue Jul 21, 2024
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's not guaranteed to have
a `__name__`, and in fact does not have one starting with Python
3.13.0b3.  Given that the `__name__` used to be `partial` before, this
change effectively preserves the old behavior for `partial`s across all
Python implementations.

Fixes encode#2638
mgorny added a commit to mgorny/starlette that referenced this issue Jul 21, 2024
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 encode#2638
mgorny added a commit to mgorny/starlette that referenced this issue Jul 24, 2024
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 encode#2638
@Kludex Kludex closed this as completed in 07427f8 Jul 24, 2024
nixroxursox pushed a commit to nixroxursox/starlette that referenced this issue Sep 30, 2024
…ncode#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 encode#2638
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants