This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: Type annotation objects (Tuple, List, etc.) register as callable()
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.9, Python 3.8, Python 3.7, Python 3.6, Python 3.5
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: Noah May, gvanrossum, levkivskyi, serhiy.storchaka
Priority: normal Keywords:

Created on 2020-04-16 07:27 by Noah May, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (2)
msg366580 - (view) Author: Noah May (Noah May) Date: 2020-04-16 07:27
Whether this is considered a bug or not is subjective. The question is should callable(Tuple) return True or False? Or should it for any other annotation object?

The reason it returns true in the first place is because of a warning to explicitly NOT call them as functions/constructors:

>>> from typing import Tuple
>>> callable(Tuple)
>>> Tuple()
TypeError: Type Tuple cannot be instantiated; use tuple() instead

Source code:

I honestly don't know how this could be "fixed" if it even needs to be fixed. But I just wanted to bring attention to it.

msg366585 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2020-04-16 08:49
It is not a bug. Tuple is a callable, but calling it raises a TypeError with the informative error message.

It does not differ from e.g.

>>> def foo():
...     raise TypeError("don't call foo()")
>>> callable(foo)
>>> foo()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 2, in foo
TypeError: don't call foo()
Date User Action Args
2022-04-11 14:59:29adminsetgithub: 84478
2020-04-16 08:49:32serhiy.storchakasetstatus: open -> closed

nosy: + serhiy.storchaka
messages: + msg366585

resolution: not a bug
stage: resolved
2020-04-16 08:07:38xtreaksetnosy: + gvanrossum, levkivskyi
2020-04-16 07:27:17Noah Maycreate