I’m using Python 3.8, and I’ve seen:
- PyLance reports subscript will generate runtime exception within TYPE_CHECKING clause
- Type subscript runtime exception false positive
What is the syntax for defining a class that inherits from a Generic type?
I’ve tried the following:
# Python 3.8
from __future__ import annotations
from collections import OrderedDict
from typing_extensions import TypeAlias
od_alias: TypeAlias = 'OrderedDict[str, int]'
class mydict(OrderedDict[str, int]): # Subscript for class "OrderedDict" will generate runtime exception; enclose type annotation in quotes
pass
class mydict(OrderedDict['str', 'int']): # Subscript for class "OrderedDict" will generate runtime exception; enclose type annotation in quotes
pass
class mydict(od_alias): # Inheriting 'od_alias', which is not a class
pass