实例化Coroutine Generator时,Pylint标记分配是从返回的。
我收到Pylint
错误,我不明白。我定义了一个生成器(我用作coroutine),即即使分配分配返回生成器而不是返回值:
E1111: Assigning result of a function call, where the function has no return (assignment-from-no-return)
最小降低示例:
def test():
print((yield))
a = test()
print(a)
next(a)
try:
a.send("hello, world")
except StopIteration:
pass
行 :行:行, pylint 抱怨的地方,即使也是如此。 a = test()
是标记错误的位置。由于test()
是一个发电机的实例化,而不是函数调用,因此我不明白错误。我尝试将(收益)
更改为(none none)
或(收益true)
无用。添加返回true
给我一个no-ember
错误。
执行:
$ python3 /tmp/test.py
<generator object test at 0x7f9de7801b30>
hello, world
是的,我可以禁用它,但是我更喜欢在禁用它之前完全理解它。
如果我将其转换为传统发电机,它不会抱怨:
def test():
yield True
a = test()
print(a)
next(a)
I am getting a pylint
error I don't understand. I defined a generator (which I am using as a coroutine), and where I instantiate the generator, pylint
complains, even though the assignment returns a generator and not a return value:
E1111: Assigning result of a function call, where the function has no return (assignment-from-no-return)
Minimum reducible example:
def test():
print((yield))
a = test()
print(a)
next(a)
try:
a.send("hello, world")
except StopIteration:
pass
The line a = test()
is where the error is flagged. Since test()
is a generator instantiation, not a function call, I don't understand the error. I tried changing (yield)
to (yield None)
or (yield True)
to no avail. Adding a return True
gives me a no-member
error.
Execution:
$ python3 /tmp/test.py
<generator object test at 0x7f9de7801b30>
hello, world
Yes, I can disable it, but I prefer to fully understand it before I disable it.
If I convert it to a traditional generator, it does not complain:
def test():
yield True
a = test()
print(a)
next(a)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论