`isinstance` on multiple-inheritance class erases type hints
Aberta
Ninguém assumiu esta issue ainda.
3.12
3.13
3.14
stdlib
topic-typing
type-bug
- Linguagem predominante
- Python
- Estrelas
- 77.2k
- Forks
- 35.9k
- Métricas de merge de PRs
- Métricas de PR pendentes
Descrição
Bug report
Bug description:
Steps to reproduce:
- Create a runtime checkable protocol
- Create one base class with type hints
- Create a second base class that satisfies the protocol
- Create a derived class that inherits from both the base classes
get_type_hintson the derived class and see they are correct- check the derived class
isinstanceof the protocol get_type_hintson the derived class and see that they are a blank dictionary
from abc import abstractmethod
from typing import Protocol, get_type_hints, runtime_checkable
@runtime_checkable
class Hello(Protocol):
@abstractmethod
def hello(self) -> str: ...
class Base:
a: str
class Base2:
def hello(self) -> str:
return "hello"
class Thing(Base, Base2): ...
def test_hints():
t = Thing()
assert get_type_hints(t) == {"a": str}
assert isinstance(t, Hello)
assert get_type_hints(t) == {"a": str}
CPython versions tested on:
3.11, 3.13
Operating systems tested on:
Linux
Guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Direção de pesquisa
Comece executando o reprodutor fornecido no CPython e compare get_type_hints antes e depois da verificação isinstance. Rastreie os caminhos de get_type_hints e runtime-checkable Protocol envolvidos nessa verificação. Está concluído quando a instância derivada de Thing ainda relatar {"a": str} após isinstance(t, Hello).
Escrita pelo modelo de indexação a partir do texto da issue.
Avaliação
- Stack de tecnologia
- python
- Domínio
- backend
- Tipo de issue
- Bug
- Dificuldade
- 4/5
- Tempo estimado
- 3-5 dias
- Status de atividade
- Estagnada
- Clareza
- Claramente especificada
- Facilidade para iniciantes
- 35/100