Protocol named "Protocol" or "Generic" has no members.
Ninguém assumiu esta issue ainda.
- 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:
If a protocol is named Protocol or Generic then it will ignore any defined members.
when you get lazy with naming in your unit tests this makes for quite a head scratcher...
Minimal Reproduction
import typing
class Protocol(typing.Protocol):
a: int
members = typing.get_protocol_members(Protocol)
assert members == {"a"}, f"Expected members to be {{'a'}}, got {members}"
Output:
Traceback (most recent call last):
File ".../test_protocol.py", line 10, in <module>
assert members == {"a"}, f"Expected members to be {{'a'}}, got {members}"
^^^^^^^^^^^^^^^^
AssertionError: Expected members to be {'a'}, got frozenset()
Expected Output:
Nothing, script should succeed without error.
Investigation
The problem appears to stem from the _get_protocol_attrs function used by _ProtocolMeta which is defined as follows:
The if statement on line 1887 is too loose in what it matches.
Possibile Fix
The check for base needs to be more specific, either using the instance itself:
if base in {Protocol, Generic}:
continue
or checking the module too, in order to ensure its the correct class being excluded:
if base.__name__ in {'Protocol', 'Generic'} and base.__module__ == 'typing':
continue
CPython versions tested on:
3.14
Operating systems tested on:
macOS
Linked PRs
- gh-145724
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 em Lib/typing.py, em _get_protocol_attrs, a função identificada no relatório, e execute a reprodução mínima fornecida com Python 3.14. O trabalho estará concluído quando uma classe definida pelo usuário chamada Protocol ou Generic expuser seus membros de protocolo declarados por meio de typing.get_protocol_members; verifique gh-145724 antes de começar, pois o issue vincula um pull request existente.
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
- 2/5
- Tempo estimado
- 1-3 horas
- Status de atividade
- Estagnada
- Clareza
- Claramente especificada
- Facilidade para iniciantes
- 35/100