Skip to content

MAINT: Enable type checking on all modules with mypy's check_untyped_defs setting enabled #3730

Open

Description

@connortann

We would like the mypy type checker to run successfully on the shap codebase with the setting check_untyped_defs = true.

However, at present this does not pass on many submodules, so they opt out from this configuration setting:

shap/pyproject.toml

Lines 104 to 108 in 86b6ee0

[[tool.mypy.overrides]]
# Disable some checks from certain shap modules
# TODO: get these passing!
module = [
"shap._explanation",

When the typing issues in a given module are fixed, the relevant exclusion in pyproject.toml should be removed.

Checklist of modules to fix:

  • __init__.py
  • _explanation.py
  • _serializable.py
  • _version.py
  • actions/__init__.py
  • actions/_action.py
  • actions/_optimizer.py
  • datasets.py
  • explainers/__init__.py
  • explainers/_additive.py
  • explainers/_deep/__init__.py
  • explainers/_deep/deep_pytorch.py
  • explainers/_deep/deep_tf.py
  • explainers/_deep/deep_utils.py
  • explainers/_exact.py
  • explainers/_explainer.py
  • explainers/_gpu_tree.py
  • explainers/_gradient.py
  • explainers/_kernel.py
  • explainers/_linear.py
  • explainers/_partition.py
  • explainers/_permutation.py
  • explainers/_sampling.py
  • explainers/_tree.py
  • explainers/other/__init__.py
  • explainers/other/_coefficient.py
  • explainers/other/_lime.py
  • explainers/other/_maple.py
  • explainers/other/_random.py
  • explainers/other/_treegain.py
  • explainers/other/_ubjson.py
  • explainers/pytree.py
  • explainers/tf_utils.py
  • links.py
  • maskers/__init__.py
  • maskers/_composite.py
  • maskers/_fixed_composite.py
  • maskers/_fixed.py
  • maskers/_image.py
  • maskers/_masker.py
  • maskers/_output_composite.py
  • maskers/_tabular.py
  • maskers/_text.py
  • models/__init__.py
  • models/_model.py
  • models/_teacher_forcing.py
  • models/_text_generation.py
  • models/_topk_lm.py
  • models/_transformers_pipeline.py
  • plots/__init__.py
  • plots/_bar.py
  • plots/_beeswarm.py
  • plots/_benchmark.py
  • plots/_decision.py
  • plots/_embedding.py
  • plots/_force_matplotlib.py
  • plots/_force.py
  • plots/_group_difference.py
  • plots/_heatmap.py
  • plots/_image.py
  • plots/_labels.py
  • plots/_monitoring.py
  • plots/_partial_dependence.py
  • plots/_scatter.py
  • plots/_text.py
  • plots/_utils.py
  • plots/_violin.py
  • plots/_waterfall.py
  • plots/colors/__init__.py
  • plots/colors/_colorconv.py
  • plots/colors/_colors.py
  • utils/__init__.py
  • utils/_clustering.py
  • utils/_exceptions.py
  • utils/_general.py
  • utils/_keras.py
  • utils/_legacy.py
  • utils/_masked_model.py
  • utils/_show_progress.py
  • utils/image.py
  • utils/transformers.py

Activity

  1. added
    enhancementIndicates new feature requests
    help wantedIndicates that a maintainer wants help on an issue or pull request
    on Jul 1, 2024
  2. BaibhavKundu2005 commented on Apr 18, 2026

    @BaibhavKundu2005
    Contributor

    Hi @connortann. I'd like to take plots/_waterfall.py and maskers/_tabular.py. I'll add the strict type hints, remove them from the pyproject.toml exclusion list, and open a PR once mypy passes locally.

  3. SarthakB11 commented on Apr 22, 2026

    @SarthakB11
    Contributor

    I've been working through the unchecked modules — PRs open for explainers/other/_random.py (#4436) and explainers/tf_utils.py (#4445), both green CI.

    Planning to continue with maskers/_image.py and plots/_force.py over the next two weeks.

  4. PredictiveManish commented on Apr 23, 2026

    @PredictiveManish

    I'm working on shap/explainers/_tree.py. made some changes currently testing them, soon will make a PR.

  5. SarthakB11 commented on Apr 23, 2026

    @SarthakB11
    Contributor

    PRs now open for maskers/_image.py (#4761), plots/_force.py (#4760), and plots/_force_matplotlib.py (#4772) — all building on the earlier work.

  6. lll-hhh commented on Nov 2, 2026

    @lll-hhh

    I would like to take the shap/explainers/_deep/deep_pytorch.py slice. On main 8dfb527, enabling check_untyped_defs for this module exposes 7 mypy diagnostics with PyTorch installed: optional interim state, the list/array attribution result, and the backward-hook gradient list. I checked all 473 open PRs and the claims here; #4219 does not modify this module, and I found no competing typing slice. Scope: resolve these internal typing issues, remove only this module from the exemption, and add small deterministic CPU tests for output ranking, multiple inputs, and interim-layer attribution to preserve numeric and return-shape behavior. No operator support or algorithm changes. AI disclosure: Codex is preparing and testing this under the user's authorization, originating from this tracker; no independent human review is claimed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementIndicates new feature requestshelp wantedIndicates that a maintainer wants help on an issue or pull request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions