-
-
Notifications
You must be signed in to change notification settings - Fork 33.1k
Closed as not planned
Labels
stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-typingtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
Bug report
Let's say we have this setup code:
from collections.abc import Callable as abc_Callable
from typing import ParamSpec, TypeVar, Callable
P = ParamSpec('P')
R = TypeVar('R')
This works correctly:
Callable[P, R][0, int] # correctly raises:
# TypeError: Expected a list of types, an ellipsis, ParamSpec, or Concatenate. Got 0
abc_Callable[P, R][0, int] # correctly raises:
# TypeError: Expected a list of types, an ellipsis, ParamSpec, or Concatenate. Got 0
We even have a test for this:
cpython/Lib/test/test_typing.py
Lines 2469 to 2477 in 6fb5f7f
def test_type_subst_error(self): | |
Callable = self.Callable | |
P = ParamSpec('P') | |
T = TypeVar('T') | |
pat = "Expected a list of types, an ellipsis, ParamSpec, or Concatenate." | |
with self.assertRaisesRegex(TypeError, pat): | |
Callable[P, T][0, int] |
But, this does not raise for some reason:
>>> Callable[P, int][0]
typing.Callable[[0], int]
>>> abc_Callable[P, int][0]
collections.abc.Callable[[0], int]
>>> Callable[P, int][0, int]
typing.Callable[[0, int], int]
>>> abc_Callable[P, int][0, int]
collections.abc.Callable[[0, int], int]
Somehow the presense of R
makes the validation correct. But, when R
is removed, we skip the ParamSpec
validation.
I would like to work on this if we decide that this is a bug indeed. I remember that we want less runtime checks. But, technically this is a regression in one of them?
Metadata
Metadata
Assignees
Labels
stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-typingtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error