Код: Выделить всё
from abc import ABC
from typing import TypeVar
from pydantic import BaseModel
_M = TypeVar("_M", bound=BaseModel)
class A(BaseModel):
a = 1
b = 2
c = 3
class Base(ABC):
cfg_model: type[_M]
def __init__(self):
self.cfg = self.cfg_model()
class ChildA(Base):
cfg_model = A
def run(self):
self.cfg_model # (variable) model_class: type[_M]
self.cfg # (variable) cfg: _M
# pylance fails to detect properties in `self.cfg`
self.cfg.a
self.cfg.b
self.cfg.c
Но я не могу этого понять. выясните, как заставить pylance (я использую код Visual Studio) правильно проверить тип self.cfg в методе ChildA run как A.
Подробнее здесь: https://stackoverflow.com/questions/789 ... nded-class