You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by "sadpandajoe (via GitHub)" <gi...@apache.org> on 2026/10/11 08:31:40 UTC
[I] mypy: Invalid index type for dict[str, Metric] in semantic_layers/mapper.py [superset]
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: notifications-unsubscribe@superset.apache.org.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [I] mypy: Invalid index type for dict[str, Metric] in semantic_layers/mapper.py [superset]
Posted by "sadpandajoe (via GitHub)" <gi...@apache.org>.
sadpandajoe closed issue #45184: mypy: Invalid index type for dict[str, Metric] in semantic_layers/mapper.py
URL: https://github.com/apache/superset/issues/45184
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org