Skip to content

Instantly share code, notes, and snippets.

@JakuWorks
Created February 7, 2024 16:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JakuWorks/d23344cf85ba7f79c35652a68cba540d to your computer and use it in GitHub Desktop.
Save JakuWorks/d23344cf85ba7f79c35652a68cba540d to your computer and use it in GitHub Desktop.
TypeVarsAttempt-#3.py
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