python / python/typeshed

Problems using SimpleXMLRPCServer.register_function

未关闭
#4,837 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

主要语言
Python
星标
5.1k
派生
2.1k
平均合并
1 天 19 小时
30 天内合并 PR
82

描述

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!

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

从 xmlrpc.server 存根和 SimpleXMLRPCServer.register_function 入口点开始,重点关注 _DispatchProtocol 回调类型。对 issue 中的最小示例运行 mypy,并将接受的无参数函数和可调用类情况与 echo_int 进行比较。当带参数的函数类型通过类型检查且不导致其他注册出现回归时,即表示完成。

由索引模型根据 Issue 内容生成。

评估

技术栈
python
领域
devtools
Issue 类型
缺陷
难度
3/5
预计耗时
1-2 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。