预期类型'Iterable [SupportsLessThan | Any]'(匹配通用类型'Iterable[SupportsLessThanT]'),取而代之的是'object'

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

以下两段代码应该是等价的:

块 1

array_1 = [[12, 15], [10, 1], [5, 13]]

print(array_1)
""" output:
[[12, 15], [10, 1], [5, 13]]
"""

print(sorted(array_1))
""" output:
[[5, 13], [10, 1], [12, 15]]
"""

第 2 区

import numpy as np

np_array_1 = np.array([[12, 15], [10, 1], [5, 13]])

print(np_array_1)
""" output:
[[12 15]
 [10  1]
 [ 5 13]]
"""

array_1 = np_array_1.tolist()

print(array_1)
""" output:
[[12, 15], [10, 1], [5, 13]]
"""

print(sorted(array_1))
""" output:
[[5, 13], [10, 1], [12, 15]]
"""

但是,在 PyCharm 中,如果我使用:

sorted(np_array_1.tolist())  # SEE BLOCK 2

我只收到这个warning,但显然没有任何问题:

Expected type 'Iterable[SupportsLessThan | Any]' (matched generic type 'Iterable[SupportsLessThanT]'), got 'object' instead

我想要干净的代码,谢谢。

python numpy sorting warnings numpy-ndarray
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.