functools.singledispatch registration prioritizes the types of normal arguments before positional-only ones
Ninguém assumiu esta issue ainda.
- Linguagem predominante
- Python
- Estrelas
- 77.2k
- Forks
- 36k
- Métricas de merge de PRs
- Métricas de PR pendentes
Descrição
Bug report
Bug description:
Decorator-based functools.singledispatch registration prioritizes the types of normal arguments before positional-only ones when getting "the type of the first argument".
This means that a function of def f(pos: str, /, other: int) will be registered to be dispatched for other's type (int) instead of pos (str).
To reproduce:
import functools
@functools.singledispatch
def f(arg, /, extra):
return f"{arg}: undispatched type"
@f.register
def f_int(arg: int, /, extra: str):
return f"{arg} is a {type(arg)} (dispatched by int)"
@f.register
def f_str(arg: str, /, extra: int):
return f"{arg} is a {type(arg)} (dispatched by str)"
print(f(None, "extra"))
print(f(1, "extra"))
print(f("s", "extra"))
Result:
None: undispatched type
1 is a <class 'int'> (dispatched by str)
s is a <class 'str'> (dispatched by int)
Expected:
None: undispatched type
1 is a <class 'int'> (dispatched by int)
s is a <class 'str'> (dispatched by str)
CPython versions tested on:
3.9, 3.10, 3.11, 3.12, 3.13, 3.14, CPython main branch
Operating systems tested on:
macOS
Linked PRs
- gh-143888
- gh-143465
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 pelo caminho de registro de functools.singledispatch e reproduza o exemplo com argumentos somente posicionais e argumentos normais. A tarefa estará concluída quando o registro selecionar o tipo do primeiro argumento somente posicional, os resultados de dispatch mostrados corresponderem à saída esperada, a cobertura de regressão tiver sido adicionada e os testes relevantes passarem.
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
- 3/5
- Tempo estimado
- 1-2 dias
- Status de atividade
- Estagnada
- Clareza
- Claramente especificada
- Facilidade para iniciantes
- 25/100