Closed
Description
Bug description
import pytest
import sys
def test_something():
if sys.platform == "linux":
cmd = "ls"
elif sys.platform == "win32":
cmd = "dir"
else:
pytest.skip("only runs on Linux/Windows")
print(cmd)
Configuration
No response
Command used
pylint -E test_x.py
Pylint output
************* Module test_x
test_x.py:12:10: E0606: Possibly using variable 'cmd' before assignment (possibly-used-before-assignment)
Expected behavior
No error: The pytest
module has a couple of functions that never return:
pytest.exit(...)
pytest.skip(...)
pytest.fail(...)
pytest.xfail(...)
Related:
- possibly-used-before-assignment doesn't understand never-returning-functions #9627
possibly-used-before-assignment
does not understandassert_never
#9643
Instead of maintaining a list of functions like this, could pylint maybe instead check whether they have a NoReturn
return type, if type information is available? That would cover assert_never()
, all the pytest functions, possibly sys.exit()
and friends (if stdlib typing information is available via typeshed), and lots and lots of other third-party cases like this.
Pylint version
pylint 3.2.1
astroid 3.2.2
Python 3.12.3 (main, Apr 23 2024, 09:16:07) [GCC 13.2.1 20240417]
OS / Environment
Archlinux
Additional dependencies
No response
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment