sadpandajoe opened a new issue, #45184: URL: https://github.com/apache/superset/issues/45184
### Problem Nightly scheduled full-repo mypy (`pre-commit run --all-files`) fails on master: `superset/semantic_layers/mapper.py:402: error: Invalid index type "AdhocMetric | str" for "dict[str, Metric]"; expected type "str" [index]`. First failing run: https://github.com/apache/superset/actions/runs/38117876493/job/114406346701 (commit e229ea4a543546b94bc3e751f611109d111cc8db). ### Root cause `_map_query_object` in `superset/semantic_layers/mapper.py:402` indexes `all_metrics` (`dict[str, Metric]`, the semantic-layer `Metric` dataclass from `superset_core.semantic_layers.types`) using entries from `query_object.metrics`, typed as `list[Metric] | None` on `QueryObject` (`superset/common/query_object.py:109`) where `Metric` is actually the unrelated alias `AdhocMetric | str` from `superset/superset_typing.py:161`. `ValidatedQueryObject` (mapper.py:116-127) already narrows `filter`, `series_columns`, and `series_limit_metric` from the base class but never narrowed `metrics`, so mypy can't see that `_validate_metrics` (mapper.py:1195) already guarantees `list[str] | None` by the time `_map_query_object` runs. ### Steps to reproduce Run an isolated mypy invocation that puts superset-core on the command line alongside mapper.py (this is what `pre-commit run --all-files` does nightly, bypassing the `follow_imports="skip"` override that normally hides this): ``` mypy superset/semantic_layers/mapper.py ``` (Found via automated investigation — [Agor](https://agor.live/).) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
