-
-
Notifications
You must be signed in to change notification settings - Fork 278
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
Avoid a global state in utils.builtin_lookup
and avoid reinstantiating TransformVisitor
#1563
Conversation
…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.
@@ -318,7 +318,7 @@ def test_borg(self) -> None: | |||
self.assertIs(built, second_built) | |||
|
|||
|
|||
class ClearCacheTest(unittest.TestCase, resources.AstroidCacheSetupMixin): | |||
class ClearCacheTest(unittest.TestCase): |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 😄
Pull Request Test Coverage Report for Build 2324393982
💛 - 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 |
There was a problem hiding this comment.
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.
Description
1
The global state of
utils.builtin_lookup()
introduced in #1460 could be stale if the builtins module had been rebuilt byAstroidManager.clear_cache()
.2
Noticed while testing (necessary to get the tests to pass): reinstantiating
TransformVisitor
inclear_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 ofTestIsinstanceInference.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
Related Issue
Fixes #1559