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:
|
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?
CC @JelleZijlstra
Bug report
Let's say we have this setup code:
This works correctly:
We even have a test for this:
cpython/Lib/test/test_typing.py
Lines 2469 to 2477 in 6fb5f7f
But, this does not raise for some reason:
Somehow the presense of
Rmakes the validation correct. But, whenRis removed, we skip theParamSpecvalidation.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?
CC @JelleZijlstra