0

Are there syntax checkers able to detect broken code based on edge cases. An example:

def run():
    for j in [0, 1]:
        if j == 0:
            yield j
        else:
            yield None


for i in run():
    print i * 2

This code is broken because None * 2 does not make sense. Are there tools to detect this kind of error ?

Thank you

4
  • NameError: j is not defined or something when you run it. Commented Oct 12, 2016 at 22:54
  • 1
    Line 10: TypeError: unsupported operand type(s) for *: 'NoneType' and 'int' Commented Oct 12, 2016 at 22:56
  • 3
    This is not a syntax error; this is a run-time semantic error. Commented Oct 12, 2016 at 22:57
  • 1
    No, your code is syntactically correct so no syntax checker can detect any problems in it. Commented Oct 12, 2016 at 22:57

2 Answers 2

3

You're looking for a type checker, not a syntax checker. Here's one attempt to make one: http://mypy-lang.org/

Sign up to request clarification or add additional context in comments.

Comments

1

You need a type checker, not a syntax checker. github.com/python/mypy

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.