Incorrect handling of methods whose name shadows an existing name

Abierto
#4,146 2 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
48/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Estancado
Stack tecnológico
python
Área
devtools

Línea de trabajo

Reproduce the failure with top/init.py and top/bar.py by running mypy -m top. Trace name resolution for the method annotation where Foo.bar shadows the imported bar module. Done means the example no longer reports Invalid type "top.Foo.bar", while the module-qualified annotation remains valid.

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

Descripción

Given the following module structure:

top
|-- __init__.py
`-- bar.py

And the following module contents:

  • top/__init__.py:
from . import bar

class Foo:
    def bar(arg: bar.Spam):
        pass
  • top/bar.py:
class Spam:
    pass

mypy -m top fails:

top/__init__.py:4: error: Invalid type "top.Foo.bar"

This is because it prematurely assumes that bar is a function, not a module.
Interestingly, regular functions do not exhibit this behaviour. The following works fine:

from . import bar

def bar(arg: bar.Spam):
    pass
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.