Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inference result shows pollution across modules #1879

Closed
jacobtylerwalls opened this issue Nov 20, 2022 · 2 comments
Closed

Inference result shows pollution across modules #1879

jacobtylerwalls opened this issue Nov 20, 2022 · 2 comments

Comments

@jacobtylerwalls
Copy link
Member

jacobtylerwalls commented Nov 20, 2022

In the pylint primer, django and music21 have nothing to do with each other, other than being located under pylint/tests/.pylint_primer_tests.

When inferring L3688 of music21/pitch.py, astroid produces an inference result showing pollution from django:

(Pdb) node
<Assign l.3686 at 0x13e663160>
(Pdb) node.value
<Attribute.fundamental l.3686 at 0x13e093b20>
(Pdb) node.value.inferred()
[<Const.NoneType l.1845 at 0x13c61e1a0>, <Const.NoneType l.1812 at 0x12bd4ebc0>, Uninferable, <Instance of django.forms.widgets.Widget at 0x5736910848>]

Steps to reproduce

  1. Check out Emit used-before-assignment for variables only defined under always false tests pylint#6677
  2. Apply this diff:
diff --git a/pylint/extensions/redefined_variable_type.py b/pylint/extensions/redefined_variable_type.py
index ae7344cc1..3cb4e78e2 100644
--- a/pylint/extensions/redefined_variable_type.py
+++ b/pylint/extensions/redefined_variable_type.py
@@ -99,6 +99,8 @@ class MultipleTypesChecker(BaseChecker):
             return
         _type = node_type(node.value)
         if _type:
+            if target.as_string() == 'fundamental':
+                breakpoint()
             self._assigns[-1].setdefault(target.as_string(), []).append(
                 (node, _type.pytype())
             )
diff --git a/tests/primer/packages_to_prime.json b/tests/primer/packages_to_prime.json
index a1fd74b4d..7f1c69175 100644
--- a/tests/primer/packages_to_prime.json
+++ b/tests/primer/packages_to_prime.json
@@ -1,62 +1,14 @@
 {
-  "astroid": {
-    "branch": "main",
-    "directories": ["astroid"],
-    "url": "https://github.com/PyCQA/astroid",
-    "pylintrc_relpath": "pylintrc"
-  },
-  "black": {
-    "branch": "main",
-    "directories": ["src/black/", "src/blackd/", "src/blib2to3/"],
-    "url": "https://github.com/psf/black"
-  },
   "django": {
     "branch": "main",
     "directories": ["django"],
     "url": "https://github.com/django/django"
   },
-  "flask": {
-    "branch": "main",
-    "directories": ["src/flask"],
-    "url": "https://github.com/pallets/flask"
-  },
   "music21": {
     "branch": "master",
     "directories": ["music21"],
     "pylintrc_relpath": ".pylintrc",
     "minimum_python": "3.10",
     "url": "https://github.com/cuthbertLab/music21"
-  },
-  "pandas": {
-    "branch": "main",
-    "directories": ["pandas"],
-    "pylint_additional_args": ["--ignore-patterns=\"test_"],
-    "url": "https://github.com/pandas-dev/pandas"
-  },
-  "psycopg": {
-    "branch": "master",
-    "directories": ["psycopg/psycopg"],
-    "url": "https://github.com/psycopg/psycopg"
-  },
-  "pygame": {
-    "branch": "main",
-    "directories": ["src_py"],
-    "url": "https://github.com/pygame/pygame"
-  },
-  "pytest": {
-    "branch": "main",
-    "directories": ["src/_pytest"],
-    "url": "https://github.com/pytest-dev/pytest"
-  },
-  "sentry": {
-    "branch": "master",
-    "directories": ["src/sentry"],
-    "url": "https://github.com/getsentry/sentry"
-  },
-  "coverage": {
-    "branch": "master",
-    "directories": ["coverage"],
-    "url": "https://github.com/nedbat/coveragepy",
-    "pylintrc_relpath": "pylintrc"
   }
 }
  1. Run the primer command:
python3 tests/primer/__main__.py run --type=pr
  1. At the breakpoint, access node.value.inferred()

Current behavior

[<Const.NoneType l.1845 at 0x13c61e1a0>, <Const.NoneType l.1812 at 0x12bd4ebc0>, Uninferable, <Instance of django.forms.widgets.Widget at 0x5736910848>]

Expected behavior

no django instances

python -c "from astroid import __pkginfo__; print(__pkginfo__.version)" output

pylint 2.16.0-dev
astroid 2.12.12
Python 3.10.1 (v3.10.1:2cd268a3a9, Dec 6 2021, 14:28:59) [Clang 13.0.0 (clang-1300.0.29.3)]

More information

See pylint primer result: pylint-dev/pylint#6677 (comment)

@Pierre-Sassoulas
Copy link
Member

Wow, nice catch !

@jacobtylerwalls
Copy link
Member Author

Can no longer reproduce. I tried checking out earlier commits and still couldn't. Will reopen if we see this again in comments on github.

@jacobtylerwalls jacobtylerwalls closed this as not planned Won't fix, can't repro, duplicate, stale Apr 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants