Skip to content

Fix a crash when __all__ exists but cannot be inferred #8741

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

Merged
merged 1 commit into from
Jun 6, 2023

Conversation

jacobtylerwalls
Copy link
Member

Type of Changes

Type
βœ“ πŸ› Bug fix

Description

Closes #8740

@jacobtylerwalls jacobtylerwalls requested a review from nickdrozd June 6, 2023 17:12
@jacobtylerwalls jacobtylerwalls changed the title Fix a crash when __all__ exists but cannot be inferred Fix a crash when __all__ exists but cannot be inferred Jun 6, 2023
@codecov
Copy link

codecov bot commented Jun 6, 2023

Codecov Report

Merging #8741 (e770b48) into main (231447c) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #8741   +/-   ##
=======================================
  Coverage   95.82%   95.82%           
=======================================
  Files         173      173           
  Lines       18381    18384    +3     
=======================================
+ Hits        17613    17616    +3     
  Misses        768      768           
Impacted Files Coverage Ξ”
pylint/checkers/variables.py 97.25% <100.00%> (+<0.01%) ⬆️


Other tests for undefined-all-variable in tests/functional/n/names_in__all__.py"""

__all__ += [] # [undefined-variable]
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not well-versed in using __all__. Is it the case that it doesn't exist until it's defined explicitly? (As opposed to being an always-defined global)

Copy link
Member Author

@jacobtylerwalls jacobtylerwalls Jun 6, 2023

Choose a reason for hiding this comment

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

I probably shouldn't have used the word "exists".

When __all__ isn't defined, you lose the ability to do:

>>> from pylint import *
>>> version
'3.0.0b1'

Is it the case that it doesn't exist until it's defined explicitly? (As opposed to being an always-defined global)

Indeed!

>>> import astroid
>>> astroid.__all__
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: module 'astroid' has no attribute '__all__'. Did you mean: '__file__'?

Copy link
Member Author

Choose a reason for hiding this comment

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

Versus

>>> pylint.__all__
['__version__', 'version', 'modify_sys_path', 'run_pylint', 'run_symilar', 'run_pyreverse']

@github-actions
Copy link
Contributor

github-actions bot commented Jun 6, 2023

πŸ€– According to the primer, this change has no effect on the checked open source code. πŸ€–πŸŽ‰

This comment was generated for commit e770b48

@@ -3046,7 +3046,10 @@ def _check_module_attrs(
def _check_all(
self, node: nodes.Module, not_consumed: dict[str, list[nodes.NodeNG]]
) -> None:
assigned = next(node.igetattr("__all__"))
try:
assigned = next(node.igetattr("__all__"))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why don't we use safe_infer here?

Copy link
Member Author

Choose a reason for hiding this comment

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

Do you know of a way to use a helper with igetattr (or to use something besides igetattr, here)?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah, of course.. Well, seems like we need safe_igetattr πŸ˜„

Copy link
Member

@Pierre-Sassoulas Pierre-Sassoulas left a comment

Choose a reason for hiding this comment

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

Thank you @jacobtylerwalls. Just wondering if an internal checker for unsafe inference wouldn't be more practical than typing astroid properly πŸ˜„

@Pierre-Sassoulas Pierre-Sassoulas added this to the 2.17.5 milestone Jun 6, 2023
@jacobtylerwalls jacobtylerwalls merged commit 331e48f into pylint-dev:main Jun 6, 2023
@jacobtylerwalls jacobtylerwalls deleted the crash-8740 branch June 6, 2023 19:19
github-actions bot pushed a commit that referenced this pull request Jun 6, 2023
Pierre-Sassoulas pushed a commit that referenced this pull request Jun 6, 2023
Pierre-Sassoulas pushed a commit that referenced this pull request Jun 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Backported Crash πŸ’₯ A bug that makes pylint crash
Projects
None yet
Development

Successfully merging this pull request may close these issues.

The undefined variable '__all__' results in an inference failed
4 participants