typed-json-dataclass icon indicating copy to clipboard operation
typed-json-dataclass copied to clipboard

Can't use from __future__ import annotations

Open hector-sab opened this issue 5 years ago • 0 comments
trafficstars

Subject of the issue

When using from __future__ import annotations (PEP 563 -- Postponed Evaluation of Annotations) I get Errors of type TypeError: isinstance() arg 2 must be a type or tuple of types

Steps to reproduce

from __future__ import annotations
from dataclasses import dataclass
from typed_json_dataclass import TypedJsonMixin

@dataclass
class B(TypedJsonMixin):
	d1: str
	d2: int

b1 = B(d1="b1", d2=1)

Expected behaviour

The following code should run without any type error

from __future__ import annotations
from typing import List
from dataclasses import dataclass, field
from typed_json_dataclass import TypedJsonMixin

@dataclass
class A(TypedJsonMixin):
	d1: str
	d2: List[B] = field(default_factory=list)

@dataclass
class B(TypedJsonMixin):
	d1: str
	d2: int

breakpoint()
b1 = B(d1="b1", d2=1)
b2 = B("b2",2)

a = A("a")

Actual behaviour

Trows the error TypeError: isinstance() arg 2 must be a type or tuple of types

hector-sab avatar Jun 13 '20 16:06 hector-sab