- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
考虑以下用例(最小示例):
def get_func(param):
if param is None:
def func():
return None
else:
def func():
return param
return func
def process_val(param):
func = get_func(param)
val = func()
# Do stuff with 'val'; *None* is an useful case.
return val
这里,func() 可以返回或不返回 None,这取决于 param 的值,但是 Pylint 为此触发 E1128,以下解释:
Used when an assignment is done on a function call but the inferred function returns nothing but None.
我很想禁用此代码的警告,但它实际上被归类为错误,这让我觉得这实际上在过去产生了错误,所以我想了解:这是 Pylint 错误吗,没有看到有时创建的函数会返回 None 以外的东西?还是可能有一个总是返回 None 的函数被认为是太糟糕的做法?也许还有其他我看不到的解释?
如果这看起来太复杂了,实际用例更像这样:
def get_func(source):
if source is None:
def func():
return None
elif source is "webcam":
# Open webcam...
def func():
# Capture frame from webcam
return frame
elif source is "server":
# Open connection to server...
def func():
# Read data from server.
return data
# Other cases...
return func
def process_val(source):
data_func = get_func(source)
# Here, do stuff in a loop, or pass *data_func* to other functions...
# The code that uses the *data_func* knows that *None* means that
# data could not be read and that's OK.
对于使用 data_func 的代码,这样比必须考虑 source 的值来决定数据是否总是 None< 更简单/em>。对我来说,这似乎是一种有效的函数式方法(也许我错了,这不是 Pythonic 方式)。
(我正在使用 Pylint 2.12.2)
最佳答案
如果该函数并不总是返回 None,那么这是 pylint 对您的代码没有很好理解的误报。如果函数总是返回 None 你没有理由将它赋值给一个变量,这意味着代码充其量只是在做一个无用的赋值,而不是按照你的想法去做,或者最坏的情况是完全错误。不确定为什么它是错误消息而不是警告。
关于python - Pylint 错误 E1128 背后的逻辑(无分配),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74467217/
我正在寻找匹配 /(?=\W)(gimme)(?=\W)/gi 或类似的东西。 \W 应该是零宽度字符来包围我的实际匹配项。 也许有一些背景。我想用添加的文字填充替换某些单词(总是 \w+),但前提是
如何在不使用 Intent 连接到 VPN 服务的情况下以编程方式检测流量是否正在通过 VPN。有系统调用吗? 最佳答案 这个有效: private boolean checkVPN() {
我是一名优秀的程序员,十分优秀!