Inconsistent error when aliasing a type from a module without stubs

Abierto
#2,801 3 comentarios 1 reacción 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

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

Línea de trabajo

Start with the reproducer in test_mypy.py and run mypy on both versions shown in the issue. Trace how the missing-stub import is handled when the type is referenced directly versus through the Collection alias. Done means the two equivalent annotations produce consistent diagnostics without incorrectly calling the alias an invalid type.

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

Descripción

bug false-positive priority-1-normal

test_mypy.py:

import pymongo # this can be any third-party module without stubs

Collection = pymongo.collection.Collection

def func(a: Collection) -> bool:
   return True

Here's the output of mypy test_mypy.py :

test_mypy.py:1: error: No library stub file for module 'pymongo'
test_mypy.py:1: note: (Stub files are from https://github.com/python/typeshed)
test_mypy.py: note: In function "func":
test_mypy.py:5: error: Invalid type "test_mypy.Collection"

However, if I change test_mypy.py to this:

import pymongo

def func(a: pymongo.collection.Collection) -> bool:
  return True

then mypy does not complain about pymongo.collection.Collection being an invalid type. This seems inconsistent/wrong, Collection is not an invalid type, it's just an alias for a type without a stub.

Lenguaje dominante
Python
Estrellas
20.6k
Forks
3.3k
Merge medio
1 d 18 h
PR fusionados (30 d)
54

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.

Más de python/mypy

Todos los issues de python/mypy

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.