python / python/mypy

mypy crashes if collections import is removed from typing.pyi

Ouverte
#16,744 2 commentaires 1 réaction 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

affects-typeshed bug
Langage dominant
Python
Étoiles
20.6k
Forks
3.3k
Métriques de merge des PR
Métriques de PR en attente

Description

Bug Report

Noticed during python/typeshed#11238: When removing the (now unnecessary) collections import from stdlib/typing.pyi, mypy 1.8.0 will crash with the following traceback:

Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "mypy/semanal.py", line 6539, in accept
  File "mypy/nodes.py", line 1310, in accept
  File "mypy/semanal.py", line 2889, in visit_assignment_stmt
  File "mypy/semanal.py", line 3393, in process_type_annotation
  File "mypy/semanal.py", line 6690, in anal_type
  File "mypy/types.py", line 955, in accept
  File "mypy/typeanal.py", line 259, in visit_unbound_type
  File "mypy/typeanal.py", line 399, in visit_unbound_type_nonoptional
  File "mypy/typeanal.py", line 6[24](https://github.com/python/typeshed/actions/runs/7411345628/job/20165674610?pr=11238#step:5:25), in try_analyze_special_unbound_type
  File "mypy/typeanal.py", line 1470, in analyze_literal_type
  File "mypy/typeanal.py", line 1484, in analyze_literal_param
  File "mypy/typeanal.py", line 1738, in named_type
  File "mypy/typeanal.py", line [25](https://github.com/python/typeshed/actions/runs/7411345628/job/20165674610?pr=11238#step:5:26)6, in lookup_fully_qualified
  File "mypy/semanal.py", line 5852, in lookup_fully_qualified
AssertionError: builtins.str

To Reproduce

Check out typeshed, install mypy, remove the collections import from typing.pyi and run ./tests/typecheck_typeshed.py, which will call mypy and include the traceback.

Your Environment

Python 3.11.6, mypy 1.8.0

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.

Piste de recherche

Reproduisez le crash en supprimant le collections import de typeshed's stdlib/typing.pyi, puis exécutez ./tests/typecheck_typeshed.py. Commencez par les chemins du traceback dans mypy/typeanal.py et mypy/semanal.py, en particulier analyze_literal_type et lookup_fully_qualified. C'est terminé lorsque la vérification de typeshed se termine sans l'AssertionError pour builtins.str.

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

Évaluation

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

Recevez les nouvelles issues par e-mail

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