Skip to content

Commit

Permalink
Merge branch 'bug/177' into 'master'
Browse files Browse the repository at this point in the history
Handle multiline strings with '# noqa'

*Description of changes*

I had overlooked a usecase of Flake8 where people use `# noqa` at the end of a multi-line string. This addresses that oversight

*Related to:*  #177

See merge request !85
  • Loading branch information
sigmavirus24 committed Jul 25, 2016
2 parents 217aa81 + 299e200 commit fc035c4
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
10 changes: 10 additions & 0 deletions docs/source/release-notes/3.0.1.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
3.0.1 -- 2016-07-25
-------------------

- Fix regression in handling of ``# noqa`` for multiline strings.
(See also `GitLab#177`_)


.. links
.. _GitLab#177:
https://gitlab.com/pycqa/flake8/issues/177
1 change: 1 addition & 0 deletions docs/source/release-notes/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ All of the release notes that have been recorded for Flake8 are organized here
with the newest releases first.

.. toctree::
3.0.1
3.0.0
2.6.2
2.6.1
Expand Down
2 changes: 1 addition & 1 deletion src/flake8/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def emit(self, record):
# Clean up after LOG config
del NullHandler

__version__ = '3.0.0'
__version__ = '3.0.1'
__version_info__ = tuple(int(i) for i in __version__.split('.') if i.isdigit())


Expand Down
12 changes: 7 additions & 5 deletions src/flake8/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,16 +425,16 @@ def _make_processor(self):
self.report('E902', 0, 0, message)
return None

def report(self, error_code, line_number, column, text):
def report(self, error_code, line_number, column, text, line=None):
# type: (str, int, int, str) -> str
"""Report an error by storing it in the results list."""
if error_code is None:
error_code, text = text.split(' ', 1)

physical_line = ''
physical_line = line
# If we're recovering from a problem in _make_processor, we will not
# have this attribute.
if getattr(self, 'processor', None):
if not physical_line and getattr(self, 'processor', None):
physical_line = self.processor.line_for(line_number)

error = (error_code, line_number, column, text, physical_line)
Expand Down Expand Up @@ -504,7 +504,7 @@ def run_logical_checks(self):

self.processor.next_logical_line()

def run_physical_checks(self, physical_line):
def run_physical_checks(self, physical_line, override_error_line=None):
"""Run all checks for a given physical line."""
for plugin in self.checks.physical_line_plugins:
self.processor.update_checker_state_for(plugin)
Expand All @@ -516,6 +516,7 @@ def run_physical_checks(self, physical_line):
line_number=self.processor.line_number,
column=column_offset,
text=text,
line=(override_error_line or physical_line),
)

self.processor.check_physical_error(error_code, physical_line)
Expand Down Expand Up @@ -611,7 +612,8 @@ def check_physical_eol(self, token):
line_no = token[2][0]
with self.processor.inside_multiline(line_number=line_no):
for line in self.processor.split_line(token):
self.run_physical_checks(line + '\n')
self.run_physical_checks(line + '\n',
override_error_line=token[4])


def find_offset(offset, mapping):
Expand Down

0 comments on commit fc035c4

Please sign in to comment.