{"record":{"id":"8059b9d10777028e","repo":"QuantConnect/Lean","slug":"call-should-have-returned-expected-type-expe-8059b9","errorCode":null,"errorMessage":"{call} should have returned {expected} ({type(expected)}) but returned {actual} ({type(actual)})","messagePattern":"(.+?) should have returned (.+?) \\((.+?)\\) but returned (.+?) \\((.+?)\\)","errorType":"exception","errorClass":"AssertionError","httpStatus":null,"severity":"error","filePath":"Algorithm.Python/GetParameterRegressionAlgorithm.py","lineNumber":42,"sourceCode":"        self.check_parameter(\"100\", self.get_parameter(\"non-existing\", \"100\"), \"GetParameter(\\\"non-existing\\\", \\\"100\\\")\")\n        self.check_parameter(100, self.get_parameter(\"non-existing\", 100), \"GetParameter(\\\"non-existing\\\", 100)\")\n        self.check_parameter(100.0, self.get_parameter(\"non-existing\", 100.0), \"GetParameter(\\\"non-existing\\\", 100.0)\")\n\n        self.check_parameter(\"10\", self.get_parameter(\"ema-fast\"), \"GetParameter(\\\"ema-fast\\\")\")\n        self.check_parameter(10, self.get_parameter(\"ema-fast\", 100), \"GetParameter(\\\"ema-fast\\\", 100)\")\n        self.check_parameter(10.0, self.get_parameter(\"ema-fast\", 100.0), \"GetParameter(\\\"ema-fast\\\", 100.0)\")\n\n        self.quit()\n\n    def check_parameter(self, expected, actual, call):\n        if expected == None and actual != None:\n            raise AssertionError(f\"{call} should have returned null but returned {actual} ({type(actual)})\")\n\n        if expected != None and actual == None:\n            raise AssertionError(f\"{call} should have returned {expected} ({type(expected)}) but returned null\")\n\n        if expected != None and actual != None and type(expected) != type(actual) or expected != actual:\n            raise AssertionError(f\"{call} should have returned {expected} ({type(expected)}) but returned {actual} ({type(actual)})\")\n","sourceCodeStart":24,"sourceCodeEnd":43,"githubUrl":"https://github.com/QuantConnect/Lean/blob/d2c3659f877bfc2b5d9dc0fc89a9c7566f45e892/Algorithm.Python/GetParameterRegressionAlgorithm.py#L24-L43","documentation":"check_parameter type/value mismatch branch (lines 41-42). Asserts get_parameter returns the expected value AND the same Python type. Fires on a wrong value or a type coercion bug (e.g. '10' string vs 10 int vs 10.0 float). Note the expression has loose operator precedence, but functionally it flags any value or type divergence from the expected.","triggerScenarios":"get_parameter returns a value whose type differs from expected (e.g. int where float expected) or whose value differs (e.g. ema-fast resolves to a number other than 10). The combined condition type(expected) != type(actual) or expected != actual is True.","commonSituations":"The int/float/string overload of get_parameter returns the wrong Python type after a refactor; the configured ema-fast value changed in config; default coercion returns the default's Python type instead of parsing the stored string into the requested type.","solutions":["Confirm the regression config value for ema-fast is exactly '10' (string) and that the typed overloads coerce correctly to int 10 and float 10.0.","Inspect each GetParameter<T> overload returns a T matching the requested type, not the raw stored string or the default's type.","If you changed ema-fast intentionally, update the expected values in the check_parameter calls."],"exampleFix":"// before: typed overload returns the raw string\npublic double GetParameter(string name, double defaultValue) => double.Parse(GetParameter(name));\n// after: fall back to default when key missing, return double\npublic double GetParameter(string name, double defaultValue)\n    => _parameters.TryGetValue(name, out var v) && double.TryParse(v, out var d) ? d : defaultValue;","handlingStrategy":"type-guard","validationCode":"# coerce and validate type explicitly\nfast = self.get_parameter(\"ema-fast\", 10)\nif not isinstance(fast, int):\n    raise TypeError(f\"ema-fast must be int, got {type(fast).__name__}: {fast!r}\")","typeGuard":"def as_int(algo, key: str, default: int) -> int:\n    v = algo.get_parameter(key, default)\n    return v if isinstance(v, int) else int(v)\n\ndef as_float(algo, key: str, default: float) -> float:\n    v = algo.get_parameter(key, default)\n    return v if isinstance(v, float) else float(v)","tryCatchPattern":null,"preventionTips":["Wrap get_parameter with typed coercion helpers instead of trusting the engine's return type.","Pin parameter types in tests and assert isinstance.","Keep the int vs float distinction explicit in defaults."],"tags":["quantconnect","lean","regression","parameters","get-parameter","type-coercion"],"backgroundTag":null,"analyzedSha":"d2c3659f877bfc2b5d9dc0fc89a9c7566f45e892","analyzedAt":"2026-08-13T13:52:21.013Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}