FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

[use before def] handle class and function definitions by ilinum · Pull Request #14203 · python/mypy · GitHub

Repository navigation

[use before def] handle class and function definitions - #14203

Merged
ilinum merged 5 commits into
python:masterfrom
ilinum:partial/classdefs
Nov 29, 2022
Merged

ilinum merged 5 commits into
python:masterfrom
ilinum:partial/classdefs

Conversation

ilinum commented Nov 27, 2022 •
edited
Loading

Copy link
Copy Markdown
Collaborator

Previously, we would ignore any class definitions and would fail to detect undefined classes and functions. This updates the logic to handle them.

Closes #686

ilinum changed the title [partially defined] handle class definitions [use before def] handle class and function definitions Nov 27, 2022

This comment has been minimized.

ilevkivskyi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

LG, but I have few questions/suggestions.

Comment thread mypy/partially_defined.py
o.body.accept(self)

def visit_class_def(self, o: ClassDef) -> None:
self.process_definition(o.name)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Why do we have enter_scope() for functions but not for classes? A variable defined in a class body will not be visible outside (as a variable, will still be available as an attribute of course)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Yep, good point. Added enter and exit scope calls (with tests that were failing before)

[case testUseBeforeDefFunc]
# flags: --enable-error-code partially-defined --enable-error-code use-before-def
foo() # E: Name "foo" is used before definition
def foo(): pass

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Just in case, could you please add test for classes within functions and vice versa? Also maybe add a test where a variable is defined in a class and then is being red outside of class.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Added tests.

Copy link
Copy Markdown
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

ilinum merged commit d094c38 into python:master Nov 29, 2022
ilinum deleted the partial/classdefs branch November 29, 2022 01:00
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

References to names before they're bound should generate an error (UnboundLocalError)

2 participants


Back | FazBrowse Home | New Git URL