python-enforce-typing
python-enforce-typing copied to clipboard
Error on nested types
In Python 3.7, type enforcing creates an error with the example code below.
Given that this is valid Python, I would expect that this runs (even if the inner str
type cannot be checked)
from dataclasses import dataclass
from typing import List, Optional
from unittest import TestCase
from enforce_typing import enforce_types
@enforce_types
@dataclass(frozen=True)
class Person:
name: str
siblings: Optional[List[str]] # can be None or a List of strings
class TestPerson(TestCase):
def test_creation(self):
siblings = ["Bob", "Clair", ]
p = Person(name="Alice", siblings=siblings) # fails here
self.assertEqual("Alice", p.name)
self.assertEqual(siblings, p.siblings)
This fails with TypeError: Subscripted generics cannot be used with class and instance checks
Running on Python 3.7 with dataclasses
0.6 and enforce-typing
1.0.0.post1