From 45ae0b9eebc1e47df1a049e75d64e25118299d65 Mon Sep 17 00:00:00 2001 From: Wouter Bolsterlee Date: Fri, 5 Aug 2016 11:15:04 +0200 Subject: [PATCH 1/3] Use str(exc) instead of exc.message ...since on py3 tokenize.TokenError does not have a 'message' attribute. See #203. --- src/flake8/processor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/flake8/processor.py b/src/flake8/processor.py index 1d0e3a4..2a4014e 100644 --- a/src/flake8/processor.py +++ b/src/flake8/processor.py @@ -247,7 +247,7 @@ class FileProcessor(object): # course, I'm going to be unsurprised to be proven wrong at a later # date. except tokenize.TokenError as exc: - raise exceptions.InvalidSyntax(exc.message, exception=exc) + raise exceptions.InvalidSyntax(str(exc), exception=exc) def line_for(self, line_number): """Retrieve the physical line at the specified line number.""" From cddf982a0a16db11bfb68bd4c620535ac44bcb4b Mon Sep 17 00:00:00 2001 From: Wouter Bolsterlee Date: Fri, 5 Aug 2016 11:16:27 +0200 Subject: [PATCH 2/3] Do not treat AttributeError as if it were an IOError ...and avoid .strerror altogether since py3 does not have it. See #203. --- src/flake8/exceptions.py | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/flake8/exceptions.py b/src/flake8/exceptions.py index 71738b2..55187bb 100644 --- a/src/flake8/exceptions.py +++ b/src/flake8/exceptions.py @@ -36,16 +36,11 @@ class InvalidSyntax(Flake8Exception): def __init__(self, *args, **kwargs): """Initialize our InvalidSyntax exception.""" - self.original_exception = kwargs.pop('exception') + self.original_exception = exc = kwargs.pop('exception') + self.error_message = str(exc) if exc is not None else '' self.error_code = 'E902' self.line_number = 1 self.column_number = 0 - try: - self.error_message = self.original_exception.message - except AttributeError: - # On Python 3, the IOError is an OSError which has a - # strerror attribute instead of a message attribute - self.error_message = self.original_exception.strerror super(InvalidSyntax, self).__init__(*args, **kwargs) From f434e9adf5ca8013a63511023d71bf210b0925b9 Mon Sep 17 00:00:00 2001 From: Ian Cordasco Date: Fri, 5 Aug 2016 06:39:08 -0500 Subject: [PATCH 3/3] Clean up usage of InvalidSyntax exception --- src/flake8/exceptions.py | 11 ++++++++--- src/flake8/processor.py | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/flake8/exceptions.py b/src/flake8/exceptions.py index 55187bb..da650f9 100644 --- a/src/flake8/exceptions.py +++ b/src/flake8/exceptions.py @@ -36,12 +36,17 @@ class InvalidSyntax(Flake8Exception): def __init__(self, *args, **kwargs): """Initialize our InvalidSyntax exception.""" - self.original_exception = exc = kwargs.pop('exception') - self.error_message = str(exc) if exc is not None else '' + exception = kwargs.pop('exception', None) + self.original_exception = exception + self.error_message = str(exception) self.error_code = 'E902' self.line_number = 1 self.column_number = 0 - super(InvalidSyntax, self).__init__(*args, **kwargs) + super(InvalidSyntax, self).__init__( + self.error_message, + *args, + **kwargs + ) class PluginRequestedUnknownParameters(Flake8Exception): diff --git a/src/flake8/processor.py b/src/flake8/processor.py index 2a4014e..a3c9a6b 100644 --- a/src/flake8/processor.py +++ b/src/flake8/processor.py @@ -247,7 +247,7 @@ class FileProcessor(object): # course, I'm going to be unsurprised to be proven wrong at a later # date. except tokenize.TokenError as exc: - raise exceptions.InvalidSyntax(str(exc), exception=exc) + raise exceptions.InvalidSyntax(exception=exc) def line_for(self, line_number): """Retrieve the physical line at the specified line number."""