-
-
Save JakuWorks/bca04ea6f88cae2c93d52f356409cdf8 to your computer and use it in GitHub Desktop.
TypeVars Attempt #2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from typing import TypeVar | |
from typing import Tuple | |
from dataclasses import dataclass | |
class A: | |
def __init__(self, a1): ... | |
@dataclass | |
class BBuilder: | |
foo: int | |
def build(self) -> tuple: | |
T = TypeVar('T', bound='B') | |
a1_i_dont_want_to_be_changeable = 123 | |
class B(A): | |
def __init__(self, a2): | |
super().__init__(a1=a1_i_dont_want_to_be_changeable) | |
return (T, B) | |
my_b_builder = BBuilder(foo=456) | |
BBuilt: Tuple[TypeVar, ...] = my_b_builder.build() | |
T2 = TypeVar('T2', bound=BBuilt[0]) # Expected type expression but received "tuple[Unknown, ...]" | |
BBuiltForReal: T2 = BBuilt[1] # Type variable "T2" has no meaning in this context | |
my_b: T2 = BBuilt(a2='foo') # Type variable "T2" has no meaning in this context # Object of type "tuple[Unknown, ...]" is not callable |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment