[issue42195] Inconsistent __args__ between typing.Callable and collections.abc.Callable

Zac Hatfield-Dodds report at bugs.python.org
Thu Oct 29 08:25:19 EDT 2020


New submission from Zac Hatfield-Dodds <zac.hatfield.dodds at gmail.com>:

The two ways of getting a parametrised Callable have inconsistent __args__:

    >>> import collections.abc, typing
    >>> typing.Callable[[int, int], int].__args__
    (int, int, int)
    >>> collections.abc.Callable[[int, int], int].__args__
    ([int, int], int)

I discovered this while working on PEP 585 support in Hypothesis [1], where it is easy enough to work around but carries a potentially serious performance cost - the list means we cannot use the type as a cache key for non-`...` argument types.  

https://bugs.python.org/issue40494 and https://bugs.python.org/issue40398 may be related.

[1] https://github.com/HypothesisWorks/hypothesis/pull/2653

----------
components: Library (Lib)
messages: 379869
nosy: Zac Hatfield-Dodds, gvanrossum, levkivskyi, serhiy.storchaka
priority: normal
severity: normal
status: open
title: Inconsistent __args__ between typing.Callable and collections.abc.Callable
type: behavior
versions: Python 3.10, Python 3.9

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue42195>
_______________________________________


More information about the Python-bugs-list mailing list