Skip to content

False positive ungrouped-imports with if os.name #10460

Description

@PhanAlexandre

Bug description

When splitting the import for Windows and Linux, Pylint give a false positive for ungrouped-imports C0412.
The only way to remove this warning is to have an if/else for each import.
I think this bug is related to issues #7735 and #3382 .
Like in both issues it's not possible to regroup the import.

import os

if os.name == "nt":
    from math import pi as 
    from pathlib import PurePosixPath
else:
    from math import e
    from pathlib import PureWindowsPath

Configuration

Command used

pylint ".\test_import.py"

Pylint output

test_import.py:8:4: C0412: Imports from package math are not grouped (ungrouped-imports)
test_import.py:9:4: C0412: Imports from package pathlib are not grouped (ungrouped-imports)

Expected behavior

Raise no issue

Pylint version

pylint 3.3.5
astroid 3.3.8
Python 3.12.5 | packaged by Anaconda, Inc. | (main, Sep 12 2024, 18:18:29) [MSC v.1929 64 bit (AMD64)]

OS / Environment

Windows

Additional dependencies

Metadata

Metadata

Assignees

No one assigned

    Labels

    Control flowRequires control flow understandingFalse Positive 🦟A message is emitted but nothing is wrong with the codeNeeds PRThis issue is accepted, sufficiently specified and now needs an implementationNeeds astroid updateNeeds an astroid update (probably a release too) before being mergable

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions