[issue40397] Refactor typing._GenericAlias
Jelle Zijlstra
report at bugs.python.org
Fri May 8 16:54:49 EDT 2020
Jelle Zijlstra <jelle.zijlstra at gmail.com> added the comment:
The most recent change here caused a regression. The following file:
```
from typing import Generic, TypeVar, Union
class CannotTransform(Exception): pass
T = TypeVar("T")
E = TypeVar("E", bound=Exception)
class Ok(Generic[T]): pass
class Err(Generic[E]): pass
Result = Union[Ok[T], Err[E]]
TResult = Result[T, CannotTransform]
TMatchResult = TResult[int]
```
Now fails with:
```
Traceback (most recent call last):
File "/Users/jzijlstra-mpbt/py/cpython/Lib/../../black/black.py", line 22, in <module>
TMatchResult = TResult[int]
File "/Users/jzijlstra-mpbt/py/cpython/Lib/typing.py", line 244, in inner
return func(*args, **kwds)
File "/Users/jzijlstra-mpbt/py/cpython/Lib/typing.py", line 704, in __getitem__
arg = arg[subargs]
File "/Users/jzijlstra-mpbt/py/cpython/Lib/typing.py", line 244, in inner
return func(*args, **kwds)
File "/Users/jzijlstra-mpbt/py/cpython/Lib/typing.py", line 695, in __getitem__
_check_generic(self, params)
File "/Users/jzijlstra-mpbt/py/cpython/Lib/typing.py", line 194, in _check_generic
raise TypeError(f"{cls} is not a generic class")
TypeError: __main__.Err[__main__.CannotTransform] is not a generic class
```
Before commit c1c7d8ead9eb214a6149a43e31a3213c52448877 it was fine. This was found when we added 3.9-dev to CI for Black (https://github.com/psf/black/pull/1393).
----------
nosy: +Jelle Zijlstra
priority: normal -> release blocker
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue40397>
_______________________________________
More information about the Python-bugs-list
mailing list