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

Avoid a global state in utils.builtin_lookup and avoid reinstantiating TransformVisitor #1563

Merged
merged 4 commits into from
May 22, 2022

Conversation

jacobtylerwalls
Copy link
Member

@jacobtylerwalls jacobtylerwalls commented May 14, 2022

Description

1
The global state of utils.builtin_lookup() introduced in #1460 could be stale if the builtins module had been rebuilt by AstroidManager.clear_cache().
2
Noticed while testing (necessary to get the tests to pass): reinstantiating TransformVisitor in clear_cache() could lead to to diverging registries of transforms.

The bug from 1 can be reproduced on prior versions by just calling clear_cache at the beginning of TestIsinstanceInference.test_isinstance_int_true. That's a public API, so I added a changelog and an explicit regression test.

The bug (2) in clear_cache itself was an unreleased issue with my changes in #1528, so I didn't doc it.

Type of Changes

Type
🐛 Bug fix

Related Issue

Fixes #1559

…ing `TransformVisitor`

This global state of `utils.builtin_lookup` could be out-of-date if the builtins module had been rebuilt by AstroidManager.clear_cache(). Also, reinstantiating `TransformVisitor` in `clear_cache()` could lead to to diverging registries of transforms.
@jacobtylerwalls jacobtylerwalls added this to the 2.12.0 milestone May 14, 2022
@@ -318,7 +318,7 @@ def test_borg(self) -> None:
self.assertIs(built, second_built)


class ClearCacheTest(unittest.TestCase, resources.AstroidCacheSetupMixin):
class ClearCacheTest(unittest.TestCase):
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to get out of the usage of this mixin. I think it masks tests that don't clean up after each other (in this case, the problems were upstream in other tests). We can keep fuzzing to find the problems.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for understanding the problem well enough so that we can stop fuzzing around 😄

@coveralls
Copy link

coveralls commented May 14, 2022

Pull Request Test Coverage Report for Build 2324393982

  • 8 of 8 (100.0%) changed or added relevant lines in 2 files are covered.
  • 1 unchanged line in 1 file lost coverage.
  • Overall coverage decreased (-0.008%) to 91.8%

Files with Coverage Reduction New Missed Lines %
astroid/manager.py 1 87.44%
Totals Coverage Status
Change from base Build 2321941977: -0.008%
Covered Lines: 9191
Relevant Lines: 10012

💛 - Coveralls

self.assertIs(inferred.value, True)

def test_builtins_inference_after_clearing_cache_manually(self) -> None:
# Not recommended to manipulate this, so we detect it and call clear_cache() instead
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In trying to cover the missed lines I just decided to support this, since it's an easy mistake to make.

@jacobtylerwalls jacobtylerwalls merged commit a0cc074 into pylint-dev:main May 22, 2022
@jacobtylerwalls jacobtylerwalls deleted the fix-global-states branch May 22, 2022 16:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Pollution test cases
3 participants