Using package multipledispatch, mypy gives error name already defined

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

还没有人认领这个 Issue。

评估

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

调研方向

首先,使用所示的 multipledispatch 定义运行报告中的示例 mypy multi.py,并确认重复名称诊断。跟踪这些重复函数定义的名称检查路径,并将其与现有的 overload 处理进行比较;当该示例在没有这些错误的情况下通过类型检查,同时普通的重复定义仍然会被诊断时,即表示完成。

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

描述

bug

Bug Report

Mypy reports errors when using package multipledispatch for overloading functions.

To Reproduce

from multipledispatch import dispatch


@dispatch(list, str)
def concatenate(a: list, b: str):
    a.append(b)
    return a


@dispatch(str, str)
def concatenate(a: str, b: str):
    return a + b


@dispatch(str, int)
def concatenate(a: str, b: int):
    return a + str(b)


@dispatch(int, str)
def concatenate(a: int, b: str):
    return str(a) + b


print(concatenate(["a", "b"], "c"))
# ['a', 'b', 'c']
print(concatenate("Hello", "World"))
# HelloWorld
print(concatenate("a", 1))
# a1
print(concatenate(2, "b"))
# 2b

Expected Behavior

No errors

Actual Behavior

mypy multi.py

multi.py:10: error: Name "concatenate" already defined on line 4
multi.py:15: error: Name "concatenate" already defined on line 4
multi.py:20: error: Name "concatenate" already defined on line 4

(Write what happened.)

Your Environment

  • Mypy version used: 0.910
  • Python version used: 3.8.6
  • Operating system and version: macOS 11.5.2
  • Installed packages:
    flake8==3.9.2
    mccabe==0.6.1
    multipledispatch==0.6.0
    mypy==0.910
    mypy-extensions==0.4.3
    pycodestyle==2.7.0
    pyflakes==2.3.1
    six==1.16.0
    toml==0.10.2
    typing-extensions==3.10.0.2
主要语言
Python
星标
20.6k
派生
3.3k
平均合并
1 天 18 小时
30 天内合并 PR
54

贡献指南

打开贡献指南

从这里开始

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

python/mypy 的其他 Issue

查看 python/mypy 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

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