python—为什么mypy不认识到mapping.get()的参数只是位置参数?

iklwldmw  于 2021-09-08  发布在  Java
关注(0)|答案(0)|浏览(213)

方法 Mapping.get 不接受关键字参数,它们只是位置参数。如果使用不当,为什么mypy无法检测到?

$ mypy --command "a: str = dict(b='yes').get('a', default='no')"
Success: no issues found in 1 source file
$ python
Python 3.9.1 (default, Jan 13 2021, 15:21:08) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-44)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> a: str = dict(b='yes').get('a', default='no')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: dict.get() takes no keyword arguments

2016年有一个pr,其中引入了一个约定,即以两个下划线开头的参数仅适用于mypy。这样的基本类型难道就不遵循这一惯例吗?我想知道为什么。
请注意,pep 570已经创建,2018年刚刚随python 3.8引入。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题