-
Notifications
You must be signed in to change notification settings - Fork 753
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
Add checks for unconsistent returns #431
Open
SylvainDe
wants to merge
6
commits into
PyCQA:main
Choose a base branch
from
SylvainDe:issue-399
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Commits on Aug 25, 2015
-
Add checks for unconsistent returns
Added in PEP 8 : """ Be consistent in return statements. Either all return statements in a function should return an expression, or none of them should. If any return statement returns an expression, any return statements where no value is returned should explicitly state this as return None, and an explicit return statement should be present at the end of the function (if reachable). """ Checking for unconsistent returns corresponds to implementing a check based on ast tree. Given an AST tree, one can easily collect return statements and check whether they return an explicit value or not. Also, from the AST tree, one can try to check whether the end of the function is reachable. Warning W740 is added for explicit inconsistent returns. Warning W741 is added for implicit inconsistent returns : when a functions explicitly returns a value at some point but does not at the (reachable) end of the function. If the end of a function is not reachable but warning is triggered, one might simply add a "return None" or an "assert False" : as one said : "Explicit is better than implicit.". Regarding the code : Implementation has been made as easy to understand as possible. The new check itself has been implemented in a new class UnconsistentReturns which uses yet another class FlowAnalysis which serves as an holder for various helper methods. Also, I took this chance to change a few details so that AST-tree checks fit more easily. This changes a few APIs. I don't know if anyone is relying on those. Regarding the tests : Adding the first AST-tree based check leads to most of the (incorrect) test code to be parsed which leads to many SyntaxError either related to a single version of Python or to all of them. A A new symbol has been to be able to convey the fact that an error is expecting only for such or such version of Python. I've fixed all issues related to SyntaxError so that they are all passing all right. I hope I haven't changed what is actually tested.
Configuration menu - View commit details
-
Copy full SHA for 3ddffd2 - Browse repository at this point
Copy the full SHA 3ddffd2View commit details
Commits on Aug 26, 2015
-
Fix comments related to unconsistent commits
Comment was made that checks should be ignored by default. This is now the case and code/documentation and tests have been updated. Also, Travis commented that a few things went wrong on pretty much all Python versions. I think I have fixed most of the issues (related to the fact that : - some AST elements have changed - sys.version_info is not a namedtuple on Python 2.6). Also, I realised that a test would fail as a SyntaxError only on Python 2.6. For that reason, I've made the version tag on error somewhat more generic. Now, it can be any prefix for a version : 2 corresponds to all Python 2 version as 2.6 correponds to 2.6 and so on...
Configuration menu - View commit details
-
Copy full SHA for 3737e32 - Browse repository at this point
Copy the full SHA 3737e32View commit details -
SyntaxErrors were reported in a slightly different place making the tests fail. Removing error location for the 3 errors involved fixes the issue.
Configuration menu - View commit details
-
Copy full SHA for c316321 - Browse repository at this point
Copy the full SHA c316321View commit details
Commits on Aug 30, 2015
-
Configuration menu - View commit details
-
Copy full SHA for fb81dc4 - Browse repository at this point
Copy the full SHA fb81dc4View commit details
Commits on Sep 7, 2015
-
Configuration menu - View commit details
-
Copy full SHA for f3e8ef5 - Browse repository at this point
Copy the full SHA f3e8ef5View commit details
Commits on Sep 21, 2015
-
Merge remote-tracking branch 'upstream/master' into issue-399
Conflicts: docs/intro.rst
Configuration menu - View commit details
-
Copy full SHA for 966dd51 - Browse repository at this point
Copy the full SHA 966dd51View commit details
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.