-
-
Save JakuWorks/d23344cf85ba7f79c35652a68cba540d to your computer and use it in GitHub Desktop.
TypeVarsAttempt-#3.py
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 dataclasses import dataclass | |
from typing import TypeVar | |
class A: | |
def __init__(self, a1): ... | |
@dataclass | |
class BBuilder: | |
foo: int | |
def build(self) -> T: # "T" is not defined | |
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) | |
T = TypeVar('T', bound=B) | |
return B | |
my_b_builder: BBuilder = BBuilder(foo=456) | |
BBuilt: T = my_b_builder.build() # "T" is not defined | |
my_b = BBuilt(a2='foo') # my_b: WhatTypeHintDoIPutHere |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment