python / python/typeshed

Problems using SimpleXMLRPCServer.register_function

Open
#4,837 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
5.1k
Forks
2.1k
Avg merge
1d 19h
Merged PRs (30d)
82

Description

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!

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the xmlrpc.server stub and the SimpleXMLRPCServer.register_function entry point, focusing on the _DispatchProtocol callback types. Run mypy on the minimal example from the issue and compare the accepted zero-argument and callable-class cases with echo_int. Done means the argument-taking function type-checks without regressing the other registrations.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.