sadpandajoe opened a new pull request, #45185:
URL: https://github.com/apache/superset/pull/45185
### SUMMARY
The nightly full-repo mypy run (`pre-commit run --all-files`) flags
`superset/semantic_layers/mapper.py:402`:
`Invalid index type "AdhocMetric | str" for "dict[str, Metric]"; expected
type "str"`. This is a name collision,
not a logic bug: `QueryObject.metrics` (superset/common/query_object.py:109)
is typed `list[Metric] | None` using
the unrelated `superset.superset_typing.Metric` alias (`AdhocMetric | str`),
while `all_metrics` at mapper.py:393
is keyed by the semantic layer's own `Metric` dataclass from
`superset_core.semantic_layers.types`. mypy only
surfaces this when `superset-core` is on the mypy command line directly (the
nightly job), since
`superset_core.*` otherwise runs with `follow_imports = "skip"`.
`ValidatedQueryObject` already narrows `filter`, `series_columns`, and
`series_limit_metric` away from their
ambiguous base types for exactly this reason, but missed `metrics`. At
runtime this was never an actual risk:
`_validate_metrics` (mapper.py:1195) already raises `ValueError` if any
`query_object.metrics` entry isn't a
plain `str`, and `validate_query_object`'s `TypeGuard[ValidatedQueryObject]`
only returns `True` after that
check passes — so by the time `_map_query_object` runs,
`query_object.metrics` is guaranteed `list[str] | None`.
This change just makes the static type match that existing runtime guarantee.
Fixes #45184
### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
N/A — static type-only fix, no UI surface.
### TESTING INSTRUCTIONS
1. `pip install -r requirements/development.txt` (or an equivalent env with
`mypy` + `apache-superset-core` installed editable)
2. Run mypy with superset-core on the command line, matching the nightly job:
`mypy --config-file pyproject.toml superset/semantic_layers/mapper.py
$(find superset-core/src -name "*.py")`
3. Confirm no `mapper.py:402` error and no new `unused-ignore` warning
4. `pytest tests/unit_tests/semantic_layers/mapper_test.py` — all 203 tests
pass unchanged
### ADDITIONAL INFORMATION
- [x] Has associated issue: Fixes #45184
- [ ] Required feature flags:
- [ ] Changes UI
- [ ] Includes DB Migration (follow approval process in SIP-59)
- [ ] Migration is atomic, supports rollback & is backwards-compatible
- [ ] Confirm DB migration upgrade and downgrade tested
- [ ] Runtime estimates and downtime expectations provided
- [ ] Introduces new feature or API
- [ ] Removes existing feature or API
--
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]