`--untyped-calls-exclude` does not exclude some packages/libraries

Ouverte
#17,699 1 commentaire 0 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

Évaluation

Difficulté
4/5
Temps estimé
3-5 jours
Accessibilité débutants
35/100
Type d'issue
Bug
Clarté
Plutôt claire
Activité
À l'abandon
Stack technique
python
Domaine
devtools

Piste de recherche

Reproduisez le rapport avec le fichier .mypy.ini fourni, les imports networkx et conda.models.MatchSpec, ainsi que la commande mypy indiquée. Commencez par suivre l’implémentation et la logique de correspondance de --untyped-calls-exclude ; le travail est terminé lorsque l’import de networkx et les appels ne produisent plus les erreurs untyped-import, no-untyped-call et Any signalées, tandis que le comportement existant de MatchSpec reste intact.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

bug

Bug Report
I have not been able to find any issues discussing a similar situation, so I'm filing this bug. I apologize in advanced if this is just a configuration issue. As best as I can currently tell, this appears to be a bug.

I have an experimental branch on conda-recipe-manager that uses conda's MatchSpec module and the networkx library. I can use --untyped-calls-exclude to prevent type checking on any use of the MatchSpec class, but I cannot do the same for anything in the networkx library. I have tried just excluding networkx in our mypy.ini file and that does not resolve my issue.

This is speculation at this point, but conda is packaged with a py.typed file, even though not every module has type annotations. networkx does not announce or include any typing. I think that might be causing a rule to fire before the exclusion rule takes effect. I say this because everything I've tried causes the following error messages to be emitted, and I do not get these errors when I exclude MatchSpec:

error: Skipping analyzing "networkx": module is installed, but missing library stubs or
py.typed marker  [import-untyped]
    import networkx as nx
    ^
error: Skipping analyzing "networkx.drawing.nx_agraph": module is installed, but
missing library stubs or py.typed marker  [import-untyped]
    from networkx.drawing.nx_agraph import graphviz_layout

I have run into this issue on mypy versions 1.10 and 1.11.

Things I have tried but have not gotten to work:

  • Only excluding networkx (either by .mypy.ini or through the command line
  • Setting disallow_any_unimported to False
  • Using import networkx without aliasing to nx
  • Specifically excluding networkx.drawing.nx_agraph in addition and without excluding networkx directly

If I do not exclude MatchSpec, I receive this error upon invoking the constructor:

error: Call to untyped function "MatchSpec" in typed context  [no-untyped-call]

And then a error: Expression has type "Any" [misc] on any line referencing the instantiated MatchSpec object.

To Reproduce

import networkx as nx
foo0 = nx.DiGraph()  # error: Expression has type "Any"  [misc]

from conda.models.MatchSpec:
foo1 = MatchSpec("")  # Works fine when excluded. If not excluded, generates: error: Call to untyped function "MatchSpec" in typed context  [no-untyped-call]
print(foo1.name)  # Works fine when excluded. If not exclude, generates: error: Expression has type "Any"  [misc]

Here is our .mypy.ini

[mypy]
# Adapted from this StackOverflow post:
# https://stackoverflow.com/questions/55944201/python-type-hinting-how-do-i-enforce-that-project-wide
python_version = 3.11

# This flag enhances the user feedback for error messages
pretty = True

# Disallow dynamic typing
disallow_any_unimported = True
disallow_any_expr = True
disallow_any_decorated = True
disallow_any_generics = True
disallow_any_explicit = True
disallow_subclassing_any = True

# Disallow untyped definitions and calls
disallow_untyped_calls = True
# Exceptions for untyped external modules
untyped_calls_exclude = conda.models.match_spec, networkx
disallow_untyped_defs = True
disallow_incomplete_defs = True
check_untyped_defs = True
disallow_untyped_decorators = True

# None and optional handling
no_implicit_optional = True

# Configuring warnings
warn_unused_ignores = True
warn_no_return = True
warn_return_any = True
warn_redundant_casts = True
warn_unreachable = True

# Misc things
strict_equality = True

# Config file
warn_unused_configs = True

Expected Behavior

I would expect that any module used from networkx would skip type-evaluation. In other words, I would expect using --untyped-calls-exclude to ignore all usage from networkx. This appears to be what happens when MatchSpec is used with the --untyped-calls-excluded option.

Actual Behavior

mypy produces many errors when networkx is used in our project because it does not ship with any type annotations.

Your Environment

  • Mypy version used: 1.10.0 and 1.11.1
  • Mypy command-line flags: mypy --config-file=.mypy.ini --cache-dir=/dev/null conda_recipe_manager/ tests/ scripts/
  • Mypy configuration options from mypy.ini (and other config files): (See above .mypy.ini)
  • Python version used: 3.12.4
Langage dominant
Python
Étoiles
20.6k
Forks
3.3k
Merge moyen
1 j 18 h
PR mergées (30 j)
54

Guide de contribution

Ouvrir le guide de contribution

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de python/mypy

Toutes les issues de python/mypy

Issues similaires

Plus d'issues Python

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.