Skip to content

Release v2.0.1#72

Merged
sco1 merged 12 commits into
masterfrom
dev-next
Mar 1, 2020
Merged

Release v2.0.1#72
sco1 merged 12 commits into
masterfrom
dev-next

Conversation

@sco1
Copy link
Copy Markdown
Owner

@sco1 sco1 commented Feb 28, 2020

Changelog

v2.0.1

Added

  • Add pep8-naming to the linting toolchain #71 Add pep8-naming to linting toolchain
  • Expand pre-commit hooks
    • Add black
    • Add check-merge-conflict
    • Add check-toml
    • Add check-yaml
    • Add end-of-file-fixer
    • Add mixed-line-ending
    • Add python-check-blanket-noqa

Changed

  • Add argument names to Argument and Function __repr__ methods to make the string more helpful to read

Fixed

Additional Details

The previous approach being taken for nesting as to use a generic_visit() on the node to visit any nested functions. However, from the bugs reported (#67, #69) it was made clear that this approach was too generic & a method for either restricting or keeping track of the depth of this generic visit was required.

Both the FunctionVisitor and ReturnVisitor classes have been rearchitected to keep track of the parent context of the nodes being visited in order to properly classify methods of nested classes and return values of nested functions, respectively.

You can view a full writeup here on discuss.python.org.

Closes: #67
Closes: #69
Closes: #70
Closes: #71

sco1 added 10 commits February 23, 2020 08:07
Using `str.find()` to locate the colon denoting the end of the function definition fails in the presence of other annotations in the same line of source code, as it identifies the location of the first colon which isn't necessarily the close of the function definition. As this closing colon should be the last instance for a line of source code, changing to `str.rfind()` should mitigate this issue.
Following the repr string is much easier without having to go back & forth between the string & the class definitions.
The previous ReturnVisitor being used to identify whether or not a function returns anything other than None was flawed in its implementation, in that it visited all return nodes, even those in nested functions, and incorrectly used them in its determination about whether or not the top-level node returns something other than None.

To fix this issue, a context switcher is implemented to keep track of the function node that contains the non-None return node. If node(s) are found, they are added to a set. The `has+only_none_returns` attribute is replaced by a property method that checks for the top-level node's presence in this set of nodes.
* By moving to a more generic visitor that keeps track of the node's context, we can more reliably discriminate between class methods and "regular" functions without needing to resort to manual iteration over child nodes. This also ends up greatly simplifying the entire visitor class as well.
* Fix typo in nested class test case, which was resulting in a mismatch between the parsed function names and the specified truth values.
@sco1 sco1 added this to the 2.0.1 milestone Feb 28, 2020
Copy link
Copy Markdown
Contributor

@GhostofGoes GhostofGoes left a comment

Choose a reason for hiding this comment

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

LTGM (and tests passed on Windows :))

Copy link
Copy Markdown
Contributor

@lemonsaurus lemonsaurus left a comment

Choose a reason for hiding this comment

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

Looks good. 👌

The context switching black magic is particularly clever.

Comment thread flake8_annotations/__init__.py
@sco1 sco1 merged commit 875ca7f into master Mar 1, 2020
@sco1 sco1 deleted the dev-next branch March 1, 2020 22:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

3 participants