Problems using SimpleXMLRPCServer.register_function
Nessuno ha ancora preso questa issue.
- Lingua principale
- Python
- Stelle
- 5.1k
- Fork
- 2.1k
- Merge medio
- 1g 19h
- PR unite (30g)
- 82
Descrizione
Hi, I seem to be having an issue getting SimpleXMLRPCServer.register_function() to co-operate with mypy type checking. It seems that the callback protocol _DispatchProtocol isn't working quite right? A function with 0 arguments, and a class with an explicit __call__ method work fine, but a function with arguments does not seem to work properly.
This seems to be similar to a couple of other already-closed issues: #4163 and #4317.
I am running mypy 0.790 under Python 3.8.5.
Here is a minimal example:
from xmlrpc.server import SimpleXMLRPCRequestHandler, SimpleXMLRPCServer
def forty_two() -> int:
return 42
def echo_int(value: int) -> int:
return value
class EchoInt(object):
def __call__(self, value: int) -> int:
return value
def main() -> None:
xml_rpc_server = SimpleXMLRPCServer(
('0.0.0.0', 8080), requestHandler=SimpleXMLRPCRequestHandler, allow_none=True
)
xml_rpc_server.register_function(forty_two)
xml_rpc_server.register_function(echo_int)
xml_rpc_server.register_function(EchoInt)
This is the error output I get from running mypy on this file, flagging only the xml_rpc_server.register_function(echo_int) statement:
test.py:22: error: Argument 1 to "register_function" of "SimpleXMLRPCDispatcher" has incompatible type "Callable[[int], int]"; expected "Union[_DispatchArity0, _DispatchArity1, _DispatchArity2, _DispatchArity3, _DispatchArity4, _DispatchArityN, None]"
Thanks!
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia dallo stub xmlrpc.server e dal punto di ingresso SimpleXMLRPCServer.register_function, concentrandoti sui tipi di callback di _DispatchProtocol. Esegui mypy sull’esempio minimo dell’issue e confronta i casi accettati di funzione senza argomenti e di classe richiamabile con echo_int. Il lavoro è completato quando il tipo di funzione che accetta argomenti supera il controllo dei tipi senza introdurre regressioni nelle altre registrazioni.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- devtools
- Tipo di issue
- Bug
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100