Skip to content
New issue

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

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

Already on GitHub? # to your account

Add "__main__" as inferred value for __name__ #2345

Merged
merged 1 commit into from
Dec 12, 2023

Conversation

jacobtylerwalls
Copy link
Member

Type of Changes

Type
✨ New feature

Description

Closes #2071

@jacobtylerwalls jacobtylerwalls added the Enhancement ✨ Improvement to a component label Dec 12, 2023
@jacobtylerwalls jacobtylerwalls added this to the 3.1.0 milestone Dec 12, 2023
@jacobtylerwalls jacobtylerwalls changed the title Add __main__ as inferred value for __name__ Add "__main__" as inferred value for __name__ Dec 12, 2023
Copy link

codecov bot commented Dec 12, 2023

Codecov Report

Merging #2345 (8bd53f0) into main (dc13d5b) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #2345   +/-   ##
=======================================
  Coverage   92.86%   92.86%           
=======================================
  Files          94       94           
  Lines       11070    11072    +2     
=======================================
+ Hits        10280    10282    +2     
  Misses        790      790           
Flag Coverage Δ
linux 92.67% <100.00%> (+<0.01%) ⬆️
pypy 91.00% <100.00%> (+<0.01%) ⬆️
windows 92.45% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
astroid/nodes/scoped_nodes/scoped_nodes.py 92.50% <100.00%> (+0.01%) ⬆️

@jacobtylerwalls jacobtylerwalls merged commit a110905 into pylint-dev:main Dec 12, 2023
@jacobtylerwalls jacobtylerwalls deleted the if-name-main branch December 12, 2023 13:18
@nickdrozd
Copy link
Contributor

This change causes an error for me:

Traceback (most recent call last):
  File "/home/nick/pylint/pylint/utils/ast_walker.py", line 91, in walk
    callback(astroid)
  File "/home/nick/pylint/pylint/checkers/variables.py", line 1642, in visit_name
    self._loopvar_name(node)
  File "/home/nick/pylint/pylint/checkers/variables.py", line 2550, in _loopvar_name
    if astmts[i].statement().parent_of(stmt) and not utils.in_for_else_branch(
       ^^^^^^^^^^^^^^^^^^^^^
  File "/home/nick/astroid/astroid/nodes/node_ng.py", line 296, in statement
    return self.parent.statement()
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/nick/astroid/astroid/nodes/scoped_nodes/scoped_nodes.py", line 414, in statement
    raise StatementMissing(target=self)
astroid.exceptions.StatementMissing: Statement not found on <Module.perf.reason l.0 at 0x7f47903a9a60>

This results in a cascade of garbage warnings.

@jacobtylerwalls
Copy link
Member Author

There's a patch for the pylint variable checker that's not in yet. I can push it up if you'd like to test with it.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Enhancement ✨ Improvement to a component
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Should infer more values for == __name__ (possibly other dunders)
3 participants