Skip to content

Pylint does not follow python import order : Builtin modules are imported before custom modules  #6535

Open
pylint-dev/astroid
#2223
@electriquo

Description

@electriquo

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:

  1. os.py an empty file
  2. test.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

added
Needs triage 📥Just created, needs acknowledgment, triage, and proper labelling
on May 7, 2022
changed the title [-]"no-member" error[/-] [+]"no-member" false-positive error[/+] on May 7, 2022
changed the title [-]"no-member" false-positive error[/-] [+]"no-member" false-positive failure[/+] on May 7, 2022
added
False Positive 🦟A message is emitted but nothing is wrong with the code
and removed
Needs triage 📥Just created, needs acknowledgment, triage, and proper labelling
on May 7, 2022
mbyrnepr2

mbyrnepr2 commented on May 7, 2022

@mbyrnepr2
Member

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 run python test.py

(venv39) programming python test.py
Fatal Python error: init_import_site: Failed to import the site module
Python runtime state: initialized
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site.py", line 589, in <module>
    main()
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site.py", line 566, in main
    known_paths = removeduppaths()
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site.py", line 127, in removeduppaths
    dir, dircase = makepath(dir)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site.py", line 92, in makepath
    dir = os.path.join(*paths)
AttributeError: module 'os' has no attribute 'path'
added
Needs PRThis issue is accepted, sufficiently specified and now needs an implementation
and removed on Jul 18, 2022
changed the title [-]"no-member" false-positive failure[/-] [+]Pylint do not follow python import order : Builtin modules are imported before custom modules [/+] on Jul 18, 2022
Pierre-Sassoulas

Pierre-Sassoulas commented on Jul 18, 2022

@Pierre-Sassoulas
Member

I can reproduce this, I wonder if the order is interpreter dependent. If that's the case we need to handle this dynamically.

ssbarnea

ssbarnea commented on Jul 18, 2022

@ssbarnea
Contributor

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.

added a commit that references this issue on Jul 18, 2022

21 remaining items

jacobtylerwalls

jacobtylerwalls commented on Jun 23, 2023

@jacobtylerwalls
Member

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!

added 2 commits that reference this issue on Jun 26, 2023
8768ec3
b8755ba
modified the milestones: 3.0.0a7, 3.0.0b1 on Jul 4, 2023
removed this from the 3.0.0b1 milestone on Jul 30, 2023
removed their assignment
on Jul 30, 2023
changed the title [-]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 [/+] on Oct 4, 2024
dubiousjim

dubiousjim commented on Oct 31, 2024

@dubiousjim

Related issues: #3665, #5151, #7289

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    False Positive 🦟A message is emitted but nothing is wrong with the codeImport systemNeeds PRThis issue is accepted, sufficiently specified and now needs an implementationNeeds astroid updateNeeds an astroid update (probably a release too) before being mergablepython 3.10

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @ssbarnea@dubiousjim@zifter@pierrecdn@Pierre-Sassoulas

      Issue actions

        Pylint does not follow python import order : Builtin modules are imported before custom modules · Issue #6535 · pylint-dev/pylint