Skip to content

Behavior of --prefer-stubs #9889

@furgerf

Description

@furgerf

Bug description

Hi, when using --prefer-stubs yes I get lots of errors around numpy - I reported some examples with numpy.

I'm not sure what the expected behavior is of --prefer-stubs - it seems that with the flag set, pylint exclusively looks at stub files but ignores other types. That's not what I'd expect from "prefer stubs", hence I'm filing this as a bug.

Ideally, I'd be able to selectively --prefer-stubs of certain modules, though that doesn't seem to be possible at the moment.

Configuration

No response

Command used

pylint --prefer-stubs yes foo.py

Pylint output

************* Module foo
foo.py:1:0: C0104: Disallowed name "foo" (disallowed-name)
foo.py:4:17: E1136: Value 'npt.NDArray' is unsubscriptable (unsubscriptable-object)
foo.py:6:20: E1133: Non-iterable value np.split(np.arange(12), 3) is used in an iterating context (not-an-iterable)
foo.py:6:4: R1721: Unnecessary use of a comprehension, use list(np.split(np.arange(12), 3)) instead. (unnecessary-comprehension)
foo.py:8:20: E1133: Non-iterable value np.diff(np.arange(12)) is used in an iterating context (not-an-iterable)
foo.py:8:4: R1721: Unnecessary use of a comprehension, use list(np.diff(np.arange(12))) instead. (unnecessary-comprehension)
foo.py:10:4: E1136: Value 'np.arange(12)' is unsubscriptable (unsubscriptable-object)

Expected behavior

I expect to only see the errors around setting up the examples:

************* Module foo
foo.py:1:0: C0104: Disallowed name "foo" (disallowed-name)
foo.py:6:4: R1721: Unnecessary use of a comprehension, use list(np.split(np.arange(12), 3)) instead. (unnecessary-comprehension)
foo.py:8:4: R1721: Unnecessary use of a comprehension, use list(np.diff(np.arange(12))) instead. (unnecessary-comprehension)

Pylint version

pylint 3.2.6
astroid 3.2.4
Python 3.11.2 (main, Feb  9 2023, 05:12:33) [GCC 10.2.1 20210110]

OS / Environment

Docker (python:3.11-slim⁠ image)

Additional dependencies

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs design proposal 🔒This is a huge feature, some discussion should happen before a PR is proposed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions