classification
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
process
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 2020-04-16 08:49 by serhiy.storchaka. 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)
True
>>> Tuple()
TypeError: Type Tuple cannot be instantiated; use tuple() instead

Source code: https://github.com/python/cpython/blob/master/Lib/typing.py#L724:L733

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.

Cheers.
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)
True
>>> foo()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 2, in foo
TypeError: don't call foo()
History
Date User Action Args
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