{"record":{"id":"0ef7a1720ed2de5d","repo":"microsoft/qlib","slug":"get-support-infra-is-not-implemented","errorCode":null,"errorMessage":"`get_support_infra` is not implemented!","messagePattern":"`get_support_infra` is not implemented!","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"qlib/backtest/utils.py","lineNumber":210,"sourceCode":"            return min(max(0, idx), self.trade_len - 1)\n\n        return clip(left), clip(right)\n\n    def __repr__(self) -> str:\n        return (\n            f\"class: {self.__class__.__name__}; \"\n            f\"{self.start_time}[{self.start_index}]~{self.end_time}[{self.end_index}]: \"\n            f\"[{self.trade_step}/{self.trade_len}]\"\n        )\n\n\nclass BaseInfrastructure:\n    def __init__(self, **kwargs: Any) -> None:\n        self.reset_infra(**kwargs)\n\n    @abstractmethod\n    def get_support_infra(self) -> Set[str]:\n        raise NotImplementedError(\"`get_support_infra` is not implemented!\")\n\n    def reset_infra(self, **kwargs: Any) -> None:\n        support_infra = self.get_support_infra()\n        for k, v in kwargs.items():\n            if k in support_infra:\n                setattr(self, k, v)\n            else:\n                warnings.warn(f\"{k} is ignored in `reset_infra`!\")\n\n    def get(self, infra_name: str) -> Any:\n        if hasattr(self, infra_name):\n            return getattr(self, infra_name)\n        else:\n            warnings.warn(f\"infra {infra_name} is not found!\")\n\n    def has(self, infra_name: str) -> bool:\n        return infra_name in self.get_support_infra() and hasattr(self, infra_name)\n","sourceCodeStart":192,"sourceCodeEnd":228,"githubUrl":"https://github.com/microsoft/qlib/blob/79633dd9506ea689e5400dea0197717b5b3d74b7/qlib/backtest/utils.py#L192-L228","documentation":"BaseInfrastructure in qlib/backtest/utils.py is an abstract base for infrastructure containers (trade exchange, accounts, etc.). get_support_infra must return the set of infrastructure names the subclass supports; the base implementation raises NotImplementedError. Because __init__ immediately calls reset_infra, which calls get_support_infra, an incomplete subclass fails at instantiation time.","triggerScenarios":"Defining a subclass of BaseInfrastructure (e.g. a custom CommonInfrastructure) without overriding get_support_infra, then constructing it; instantiation raises before any other method runs.","commonSituations":"Users extend qlib's common_infra mechanism to inject custom components and forget the abstract method; silent bugs when a method named get_support_infra is misspelled or returns None instead of a set of strings, causing reset_infra to ignore every kwarg and get() to fail later.","solutions":["Implement get_support_infra in the subclass returning the set of supported infra keys, e.g. {'trade_exchange', 'trade_account'}.","Prefer composing with the existing CommonInfrastructure (register/replace components via reset_infra kwargs) instead of subclassing.","Check spelling/signature — the method takes only self and must return a Set[str]."],"exampleFix":"# before\nclass MyInfra(BaseInfrastructure):\n    pass  # -> NotImplementedError at construction\n# after\nclass MyInfra(BaseInfrastructure):\n    def get_support_infra(self):\n        return {'trade_exchange', 'trade_account'}","handlingStrategy":"validation","validationCode":"from qlib.backtest.utils import BaseInfrastructure\nclass MyInfra(BaseInfrastructure):\n    def get_support_infra(self):\n        return {'trade_exchange', 'trade_account'}\n# verify before instantiation\nassert MyInfra.get_support_infra is not BaseInfrastructure.get_support_infra","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Prefer composing via existing CommonInfrastructure over subclassing BaseInfrastructure.","When subclassing is needed, implement all abstract methods first and cover with a smoke-instantiation test."],"tags":["qlib","backtest","abstract-class","infrastructure"],"backgroundTag":null,"analyzedSha":"79633dd9506ea689e5400dea0197717b5b3d74b7","analyzedAt":"2026-08-15T07:01:27.511Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}