admin管理员组文章数量:1026989
Today, I went to Ruff playground, enabled PLR1711 (useless-return) rule and pasted this code:
def f() -> int:
print()
return None
In Diagnostics tab I saw only Everything is looking good!
.
I then removed -> int
for the code to be:
def f():
print()
return None
and saw Useless `return` statement at end of function (PLR1711) [Ln 3, Col 5]
.
Ruff complained in the same way when I annotated function to return None:
def f() -> None:
print()
return None
All the same goes for cases with return
instead of return None
.
Is this an intended behavior? If it is, I think the documentation on this rule should inform about this.
I have checked how pylint handles such cases by running cell with the following in fresh google colab runtime:
!pip install pylint>/dev/null
!printf 'def f() -> int:\n print()\n return None' > a.py
!pylint --version && pylint --disable C a.py
I got
pylint 3.3.1
astroid 3.3.5
Python 3.10.12 (main, Sep 11 2024, 15:47:36) [GCC 11.4.0]
************* Module a
a.py:1:0: R1711: Useless return at end of function or method (useless-return)
-----------------------------------
Your code has been rated at 6.67/10
So how can I get ruff to complain about useless return statements in cases when function is annotated to return not None? Do we have to wait for an update for this?
You can also help on github
Today, I went to Ruff playground, enabled PLR1711 (useless-return) rule and pasted this code:
def f() -> int:
print()
return None
In Diagnostics tab I saw only Everything is looking good!
.
I then removed -> int
for the code to be:
def f():
print()
return None
and saw Useless `return` statement at end of function (PLR1711) [Ln 3, Col 5]
.
Ruff complained in the same way when I annotated function to return None:
def f() -> None:
print()
return None
All the same goes for cases with return
instead of return None
.
Is this an intended behavior? If it is, I think the documentation on this rule should inform about this.
I have checked how pylint handles such cases by running cell with the following in fresh google colab runtime:
!pip install pylint>/dev/null
!printf 'def f() -> int:\n print()\n return None' > a.py
!pylint --version && pylint --disable C a.py
I got
pylint 3.3.1
astroid 3.3.5
Python 3.10.12 (main, Sep 11 2024, 15:47:36) [GCC 11.4.0]
************* Module a
a.py:1:0: R1711: Useless return at end of function or method (useless-return)
-----------------------------------
Your code has been rated at 6.67/10
So how can I get ruff to complain about useless return statements in cases when function is annotated to return not None? Do we have to wait for an update for this?
You can also help on github
本文标签:
版权声明:本文标题:python - How to make ruff complain about useless return statements in functions annotated to return not None? - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745659470a2161799.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论