Skip to content
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
wants to merge 6 commits into
base: main
Choose a base branch
from

Commits on Aug 25, 2015

  1. 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.
    SylvainDe committed Aug 25, 2015
    Configuration menu
    Copy the full SHA
    3ddffd2 View commit details
    Browse the repository at this point in the history

Commits on Aug 26, 2015

  1. 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...
    SylvainDe committed Aug 26, 2015
    Configuration menu
    Copy the full SHA
    3737e32 View commit details
    Browse the repository at this point in the history
  2. Fix tests on pypy

    SyntaxErrors were reported in a slightly different
    place making the tests fail. Removing error location
    for the 3 errors involved fixes the issue.
    SylvainDe committed Aug 26, 2015
    Configuration menu
    Copy the full SHA
    c316321 View commit details
    Browse the repository at this point in the history

Commits on Aug 30, 2015

  1. Enhance tests

    SylvainDe committed Aug 30, 2015
    Configuration menu
    Copy the full SHA
    fb81dc4 View commit details
    Browse the repository at this point in the history

Commits on Sep 7, 2015

  1. Configuration menu
    Copy the full SHA
    f3e8ef5 View commit details
    Browse the repository at this point in the history

Commits on Sep 21, 2015

  1. Merge remote-tracking branch 'upstream/master' into issue-399

    Conflicts:
    	docs/intro.rst
    SylvainDe committed Sep 21, 2015
    Configuration menu
    Copy the full SHA
    966dd51 View commit details
    Browse the repository at this point in the history