`singledispatchmethod` inspected signature incorrectly includes `self`
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:
The result of singledispatchmethod.__get__ is wrapped to imitate the underlying function, instead of the result of func.__get__. This leads to an incorrect signature being reported by inspect.signature, which includes the leading self argument, thus misleading introspection tools as to the real arguments the method accepts.
import inspect
from functools import singledispatchmethod
class A:
@singledispatchmethod
def a(self, arg):
pass
sig = inspect.signature(A().a)
# <Signature (self, arg)> but we expect <Signature (arg)>
sig.bind(None) # should be OK because `A().a(None)` is OK. Instead:
# TypeError: missing a required argument: 'arg'
# because the first argument is erroneously bound to `self`.
One way to fix this might be to edit https://github.com/python/cpython/blob/6258844c27e3b5a43816e7c559089a5fe0a47123/Lib/functools.py#L979 to read instead
update_wrapper(_method, self.func.__get__(obj, cls))
CPython versions tested on:
3.10, 3.12
Operating systems tested on:
Linux, Windows
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
Leia Lib/functools.py por volta da linha 979, concentrando-se em como singledispatchmethod.get envolve o método vinculado. Execute a reprodução fornecida de inspect.signature e sig.bind; está concluído quando a assinatura vinculada omitir self, aceitar o argumento real do método 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
- tooling
- Tipo de issue
- Bug
- Dificuldade
- 2/5
- Tempo estimado
- 1-3 horas
- Status de atividade
- Estagnada
- Clareza
- Claramente especificada
- Facilidade para iniciantes
- 68/100