Mailing List Archive

[issue44404] tkinter's after() AttributeError with functools.partial (no attribute __name__)
New submission from Philip Sundt <phil.tgd@gmail.com>:

```
>>> import tkinter
>>> from functools import partial
>>> r=tkinter.Tk()
>>> r.after(500, partial(print, "lol"))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3.7/tkinter/__init__.py", line 755, in after
callit.__name__ = func.__name__
AttributeError: 'functools.partial' object has no attribute '__name__'
```

----------
components: Tkinter
messages: 395712
nosy: phil.tgd
priority: normal
severity: normal
status: open
title: tkinter's after() AttributeError with functools.partial (no attribute __name__)
type: behavior
versions: Python 3.9

_______________________________________
Python tracker <report@bugs.python.org>
<https://bugs.python.org/issue44404>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue44404] tkinter's after() AttributeError with functools.partial (no attribute __name__) [ In reply to ]
E. Paine <xepaine13@gmail.com> added the comment:

Reproducible in Python 3.9. The issue occurs because functools.partial is a class, not function. I believe the fix is simply something like:

try:
callit.__name__ = func.__name__
except AttributeError:
callit.__name__ = type(func).__name__

This will use the name 'partial'. The lack of '__name__' is noted in the functools docs so I agree with Philip that this is an issue with tkinter. Philip, do you want to open a pull request for this?

It should be noted that functools.partial is not required in this situation as 'after' takes arguments for the function call:
r.after(500, print, "lol")

----------
nosy: +epaine, serhiy.storchaka
versions: +Python 3.10, Python 3.11

_______________________________________
Python tracker <report@bugs.python.org>
<https://bugs.python.org/issue44404>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue44404] tkinter's after() AttributeError with functools.partial (no attribute __name__) [ In reply to ]
Terry J. Reedy <tjreedy@udel.edu> added the comment:

The docstring for .after says the 2nd argument must be a 'function'. Whether this issue is a bugfix or enhancement request depends whether one interprets 'function' as 'callable' or something narrower that only includes objects that necessarily have __name__ attributes. The latter would exclude partials and instances of user classes with __call__ methods.

While a one-time-use partial as in the example is superfluous, I think other uses and parameterized callback classes should be supported. So I agree with changing the tkinter code rather than qualifying 'function' with 'has a .__name__ attribute'. I think 'type(func).__name__' should be safe.

----------
nosy: +terry.reedy

_______________________________________
Python tracker <report@bugs.python.org>
<https://bugs.python.org/issue44404>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue44404] tkinter's after() AttributeError with functools.partial (no attribute __name__) [ In reply to ]
Change by E. Paine <xepaine13@gmail.com>:


----------
keywords: +patch
pull_requests: +25394
stage: -> patch review
pull_request: https://github.com/python/cpython/pull/26812

_______________________________________
Python tracker <report@bugs.python.org>
<https://bugs.python.org/issue44404>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue44404] tkinter's after() AttributeError with functools.partial (no attribute __name__) [ In reply to ]
Serhiy Storchaka <storchaka+cpython@gmail.com> added the comment:


New changeset e9c8f784fa13ea3a51df3b72a498a3896ec9e768 by E-Paine in branch 'main':
bpo-44404: tkinter `after` support callable classes (GH-26812)
https://github.com/python/cpython/commit/e9c8f784fa13ea3a51df3b72a498a3896ec9e768


----------

_______________________________________
Python tracker <report@bugs.python.org>
<https://bugs.python.org/issue44404>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue44404] tkinter's after() AttributeError with functools.partial (no attribute __name__) [ In reply to ]
Serhiy Storchaka <storchaka+cpython@gmail.com> added the comment:

It is on borderline between new feature and bugfix (depends on your interpretation of the documentation), so I decided to backport it to not yet released 3.10, but not to 3.9 which has been already used for a year.

----------
stage: patch review ->
type: behavior -> enhancement
versions: -Python 3.9

_______________________________________
Python tracker <report@bugs.python.org>
<https://bugs.python.org/issue44404>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue44404] tkinter's after() AttributeError with functools.partial (no attribute __name__) [ In reply to ]
Terry J. Reedy <tjreedy@udel.edu> added the comment:

I was thinking the same.

----------

_______________________________________
Python tracker <report@bugs.python.org>
<https://bugs.python.org/issue44404>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue44404] tkinter's after() AttributeError with functools.partial (no attribute __name__) [ In reply to ]
E. Paine <xepaine13@gmail.com> added the comment:

Can this issue be closed?

----------

_______________________________________
Python tracker <report@bugs.python.org>
<https://bugs.python.org/issue44404>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue44404] tkinter's after() AttributeError with functools.partial (no attribute __name__) [ In reply to ]
Change by miss-islington <mariatta.wijaya+miss-islington@gmail.com>:


----------
nosy: +miss-islington
nosy_count: 4.0 -> 5.0
pull_requests: +25494
stage: -> patch review
pull_request: https://github.com/python/cpython/pull/26921

_______________________________________
Python tracker <report@bugs.python.org>
<https://bugs.python.org/issue44404>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue44404] tkinter's after() AttributeError with functools.partial (no attribute __name__) [ In reply to ]
Terry J. Reedy <tjreedy@udel.edu> added the comment:

When the backport is done or Serhiy changes his mind.

Can you change labels on your own PRs?

----------
nosy: -miss-islington
stage: patch review ->

_______________________________________
Python tracker <report@bugs.python.org>
<https://bugs.python.org/issue44404>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue44404] tkinter's after() AttributeError with functools.partial (no attribute __name__) [ In reply to ]
Change by Terry J. Reedy <tjreedy@udel.edu>:


----------
stage: -> patch review

_______________________________________
Python tracker <report@bugs.python.org>
<https://bugs.python.org/issue44404>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue44404] tkinter's after() AttributeError with functools.partial (no attribute __name__) [ In reply to ]
miss-islington <mariatta.wijaya+miss-islington@gmail.com> added the comment:


New changeset e1f3bd2bb50a76ba15a2f8d561e2c9968ae3a1b2 by Miss Islington (bot) in branch '3.10':
bpo-44404: tkinter `after` support callable classes (GH-26812)
https://github.com/python/cpython/commit/e1f3bd2bb50a76ba15a2f8d561e2c9968ae3a1b2


----------
nosy: +miss-islington

_______________________________________
Python tracker <report@bugs.python.org>
<https://bugs.python.org/issue44404>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue44404] tkinter's after() AttributeError with functools.partial (no attribute __name__) [ In reply to ]
Serhiy Storchaka <storchaka+cpython@gmail.com> added the comment:

There were some issues with the backporting bot. Seems they were temporary.

Thank you for your contribution E. Paine. For this issue and others.

----------
resolution: -> fixed
stage: patch review -> resolved
status: open -> closed

_______________________________________
Python tracker <report@bugs.python.org>
<https://bugs.python.org/issue44404>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue44404] tkinter's after() AttributeError with functools.partial (no attribute __name__) [ In reply to ]
E. Paine <xepaine13@gmail.com> added the comment:

> Can you change labels on your own PRs?

Sadly not (hence why I need to ask for e.g. skip news)

----------

_______________________________________
Python tracker <report@bugs.python.org>
<https://bugs.python.org/issue44404>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com