python / python/mypy

Mypy doesn't see typing info when it checks the whole package

Abierto
#10,260 4 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

bug topic-usability
Lenguaje dominante
Python
Estrellas
20.6k
Forks
3.3k
Métricas de merge de PR
Métricas de PR pendientes

Descripción

Bug Report

Mypy returns errors when it's used to check the whole package but doesn't return any errors when it's run on individual files.

These errors are the same as when you don't have corresponding package (zeroconf in this case) installed. But zeroconf==0.29.0 is installed and it exports typing information (marked with py.typed).

Maybe I'm doing something wrong but I don't get why mypy can't see this typing info.

❯ mypy homeassistant
homeassistant/components/zeroconf/models.py:3: error: Module 'zeroconf' has no attribute 'DNSPointer'  [attr-defined]
homeassistant/components/zeroconf/models.py:3: error: Module 'zeroconf' has no attribute 'DNSRecord'  [attr-defined]
homeassistant/components/zeroconf/models.py:3: error: Module 'zeroconf' has no attribute 'ServiceBrowser'  [attr-defined]
homeassistant/components/zeroconf/models.py:3: error: Module 'zeroconf' has no attribute 'Zeroconf'  [attr-defined]
homeassistant/components/zeroconf/models.py:6: error: Class cannot subclass 'Zeroconf' (has type 'Any')  [misc]
homeassistant/components/zeroconf/models.py:15: error: Class cannot subclass 'ServiceBrowser' (has type 'Any')  [misc]
homeassistant/components/zeroconf/usage.py:23: error: Name 'zeroconf.Zeroconf' is not defined  [name-defined]
homeassistant/components/zeroconf/usage.py:29: error: Name 'zeroconf.Zeroconf' is not defined  [name-defined]
homeassistant/components/zeroconf/__init__.py:13: error: Module 'zeroconf' has no attribute 'Error'  [attr-defined]
homeassistant/components/zeroconf/__init__.py:13: error: Module 'zeroconf' has no attribute 'InterfaceChoice'  [attr-defined]
homeassistant/components/zeroconf/__init__.py:13: error: Module 'zeroconf' has no attribute 'IPVersion'  [attr-defined]
homeassistant/components/zeroconf/__init__.py:13: error: Module 'zeroconf' has no attribute 'NonUniqueNameException'  [attr-defined]
homeassistant/components/zeroconf/__init__.py:13: error: Module 'zeroconf' has no attribute 'ServiceInfo'  [attr-defined]
homeassistant/components/zeroconf/__init__.py:13: error: Module 'zeroconf' has no attribute 'ServiceStateChange'  [attr-defined]
homeassistant/components/zeroconf/__init__.py:13: error: Module 'zeroconf' has no attribute 'Zeroconf'  [attr-defined]
Found 15 errors in 3 files (checked 3823 source files)

❯ mypy homeassistant/components/zeroconf/models.py
Success: no issues found in 1 source file

❯ mypy homeassistant/components/zeroconf/__init__.py
Success: no issues found in 1 source file

❯ mypy homeassistant/components/zeroconf/usage.py
Success: no issues found in 1 source file

This may be relevant. Sometimes I have mypy crashing with:

❯ mypy homeassistant
Traceback (most recent call last):
  File "/Users/sayfutdinov/Project/github/core/venv/bin/mypy", line 8, in <module>
    sys.exit(console_entry())
  File "/Users/sayfutdinov/Project/github/core/venv/lib/python3.9/site-packages/mypy/__main__.py", line 11, in console_entry
    main(None, sys.stdout, sys.stderr)
  File "mypy/main.py", line 90, in main
  File "mypy/build.py", line 179, in build
  File "mypy/build.py", line 253, in _build
  File "mypy/build.py", line 2638, in dispatch
  File "mypy/build.py", line 2955, in process_graph
  File "mypy/build.py", line 3033, in process_fresh_modules
  File "mypy/build.py", line 1977, in fix_cross_refs
  File "mypy/fixup.py", line 26, in fixup_module
  File "mypy/fixup.py", line 77, in visit_symbol_table
  File "mypy/fixup.py", line 301, in lookup_qualified_stnode
  File "mypy/lookup.py", line 47, in lookup_fully_qualified
AssertionError: Cannot find component 'DNSPointer' for 'zeroconf.DNSPointer'

This is probably related to https://github.com/python/mypy/issues/7281
It disappears after removing .mypy_cache but may appear again after some time.

To Reproduce
I'm experiencing this on https://github.com/home-assistant/core/pull/48450

  1. git clone https://github.com/home-assistant/core.git && cd core
  2. git fetch origin pull/48450/head:zeroconf-typing
  3. git checkout zeroconf-typing
  4. script/setup
  5. source venv/bin/activate
  6. pip install xknx zeroconf
  7. mypy homeassistant

Expected Behavior

Mypy doesn't return errors in all these cases.

Actual Behavior

Mypy returns errors when it's run for the whole package but doesn't return any errors when it's run on individual files.

Your Environment

  • Mypy version used: mypy 0.812
  • Mypy command-line flags: mypy homeassistant
  • Mypy configuration options from mypy.ini (and other config files): setup.cfg
  • Python version used: 3.9.2
  • Operating system and version: MacOS, Ubuntu

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Reproduce los comandos de whole-package y single-file del issue, incluido el comportamiento de limpieza de la caché. Empieza siguiendo el flujo de procesamiento de paquetes en mypy/build.py y, después, inspecciona fixup.py y lookup.py alrededor de la assertion indicada. El trabajo estará terminado cuando la comprobación de paquetes completos gestione de forma coherente la información de typing de zeroconf sin los errores indicados ni un fallo relacionado con la caché.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
python
Área
devtools
Tipo de issue
Error
Dificultad
4/5
Tiempo estimado
3-5 días
Estado de actividad
Estancado
Claridad
Bastante claro
Aptitud para principiantes
38/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.