Description
Bug description
when a project holds a module name that shadows builtin module name, pylist fails on no-member
, when clearly this is not the case.
reproduction
given 2 files:
os.py
an empty filetest.py
with the following content"""test.py""" import os print(os.environ['SHELL'])
and now pylint fails on no-member
as follows
$ pylint **/*.py
************* Module test
test.py:4:6: E1101: Module 'os' has no 'environ' member (no-member)
------------------------------------------------------------------
Your code has been rated at 0.00/10 (previous run: 0.00/10, +0.00)
but the code is correct
$ python test.py
/usr/local/bin/bash
Configuration
No response
Command used
pylint **/*.py
Pylint output
************* Module test
test.py:4:6: E1101: Module 'os' has no 'environ' member (no-member)
------------------------------------------------------------------
Your code has been rated at 0.00/10 (previous run: 0.00/10, +0.00)
Expected behavior
pylint should be aware of the import
tree, and report such issue if that is indeed the case.
in the reproduction snippet above, test.py
imports the os
builtin module (and not os.py
) that has the environ()
.
Pylint version
pylint 2.13.8
astroid 2.11.4
Python 3.10.3 (main, Mar 17 2022, 09:46:58) [Clang 13.1.6 (clang-1316.0.21.2)]
OS / Environment
macos
$ sw_vers
ProductName: macOS
ProductVersion: 12.3.1
BuildVersion: 21E258
Additional dependencies
No response
Activity
[-]"no-member" error[/-][+]"no-member" false-positive error[/+][-]"no-member" false-positive error[/-][+]"no-member" false-positive failure[/+]mbyrnepr2 commentedon May 7, 2022
In my case I haven't been able to reproduce the
no-member
. I see an issue for Python in this situation also:Create
os.py
in the current directory and runpython test.py
six.with_metaclass()
pylint-dev/astroid#1622[-]"no-member" false-positive failure[/-][+]Pylint do not follow python import order : Builtin modules are imported before custom modules [/+]Pierre-Sassoulas commentedon Jul 18, 2022
I can reproduce this, I wonder if the order is interpreter dependent. If that's the case we need to handle this dynamically.
ssbarnea commentedon Jul 18, 2022
I encountered this issue multiple times over the last month and that is because my main python is 3.11 and pylint is not yet compatible with 3.11.
So, I forced us to use oldest supported python and lock it during linting. I hope to see py311 support added soon in astroid.
Fix pylint errors
21 remaining items
jacobtylerwalls commentedon Jun 23, 2023
I would be grateful for anyone's input on pylint-dev/astroid#2223, which should fix the OP.
By installing from that branch and retesting your use case, you can give us the confidence to make changes to a delicate part of this tool's system. Thanks!
Prefer stdlib modules over same-named modules on sys.path
Prefer stdlib modules over same-named modules on sys.path
CI: downgrade Python lint task to Ubuntu 22.04
[-]Pylint do not follow python import order : Builtin modules are imported before custom modules [/-][+]Pylint does not follow python import order : Builtin modules are imported before custom modules [/+]import-self
false positive when importing non-existing module from current package #3748dubiousjim commentedon Oct 31, 2024
Related issues: #3665, #5151, #7289