Pylint:E1131:| 不支持的操作数类型(不支持的二进制操作)与 python 3.12

问题描述 投票:0回答:1

基于 PEP 604 上面的代码应该通过 pylint 检查:

# test.py
def f1(a: int | str):
    print(a)

但是我得到的结果是:

$ pylint test.py
************* Module test
test.py:3:10: E1131: unsupported operand type(s) for | (unsupported-binary-operation)

-----------------------------------
Your code has been rated at 0.00/10

导入注解不会遇到这个问题:

# test.py
from __future__ import annotations


def f1(a: int | str):
    print(a)
$ pylint test.py                                                                                                                                                                       TestPlatform [ hero6api/external_device][!?⇡][ v3.12.0(.venv)]

--------------------------------------------------------------------
Your code has been rated at 10.00/10 (previous run: 0.00/10, +10.00)

[环境]
蟒蛇版本:3.12
木柱:3.03

这个问题还没有解决吗?或者我犯了一些错误。感谢您回复我!

python-3.x pylint
1个回答
0
投票

[已关闭] 我检查了我的工作空间,发现里面有

.pylintrc
。有一行带有
py-version=3.8
。只需编辑这一行即可。

© www.soinside.com 2019 - 2024. All rights reserved.