bbcmicrobit / micropython

Port of MicroPython for the BBC micro:bit
https://microbit-micropython.readthedocs.io
Other
603 stars 284 forks source link

This should be an IndentationError #611

Closed rhubarbdog closed 5 years ago

rhubarbdog commented 5 years ago

This code generates a SyntaxError, but it should create an IndentationError

class dummy():
    def __init__(self):
        self.variable = 42

    def method(self):
    # comment                                                                   
    self.variable += 1

    def __str__(self):
        return str(self.variable)

obj = dummy()

obj.method()
print(obj)
dpgeorge commented 5 years ago

Thanks for the report. A simplified example that exhibits the same behaviour is:

if x:
pass

This is really something to address upstream in the main MicroPython repository. But in my opinion it's not worth fixing: it would be cost extra code for a rarely hit case. And anyway, IndentationError is a subclass of SyntaxError, so SyntaxError is technically correct, just a less specific error.

rhubarbdog commented 5 years ago

Yes that's fair. Is it worth not implementing IndentationError at all and saving a few bytes

microbit-carlos commented 5 years ago

Thank you @rhubarbdog for the report and @dpgeorge for the explanation. Since it looks like the original question has been answered I'll close this issue.