diff options
author | Aaron Meurer <asmeurer@gmail.com> | 2019-02-09 06:48:50 -0700 |
---|---|---|
committer | Ian Stapleton Cordasco <graffatcolmingov@gmail.com> | 2019-02-09 07:48:50 -0600 |
commit | 6ba3f8e0b59b8fe880345be7ae594ccd76661f6d (patch) | |
tree | b839692624e230ecfc4e986ef2956245ccdcdf47 | |
parent | ba64624f38a55f162b90120b4c0ba62018c6fd08 (diff) | |
download | pyflakes-6ba3f8e0b59b8fe880345be7ae594ccd76661f6d.tar.gz |
Include column numbers with all error messages (#426)
* Include column numbers with all error messages
As long as the node passed to the message has a col_offset, it is included in
the message. There is already a precedent of printing the column number for
syntax errors.
This changes the API slightly, in that if col_offset is not present on the
node, the message.col is now -1 instead of 0. Otherwise, there would be no way
to distinguish between errors that have no column number and errors with a
column number 0. If this doesn't seem like an acceptable change, I can revert
it, and either always use 0 as the default, or use a separate attribute to
indicate if the message.col is the "real" column number.
I haven't yet tested everything, but I'm not even sure if there are any nodes
that don't have a col_offset. There don't appear to be any represented in the
test suite.
* Simplify some code
* Make column numbers start at 1
This also reverts an API break. message.col now defaults to 0 again, instead
of -1 (0 means there is no column number and so it isn't included in the
printed error message).
* Revert column number API change
It broke a lot of tests.
Now, to minimize API changes as much as possible:
- The message.col attribute starts at 0, same as the AST col_offset
- message.col is also 0 even if col_offset doesn't exist. Note that currently
there aren't any nodes represented in the pyflakes test suite that don't
have col_offset. Such nodes do exist in the ast module, but it seems
unlikely that they would ever result in a message (only expr and stmt nodes
have it, so for instance a Module node would not).
- The str version of the message starts columns at 1, which is consistent with
the existing messages for syntax errors, as well as other tools such as
flake8.
* Fix flake8 issue
Fixes #158
Fixes #425
-rw-r--r-- | pyflakes/messages.py | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/pyflakes/messages.py b/pyflakes/messages.py index f73ba46..8ae545f 100644 --- a/pyflakes/messages.py +++ b/pyflakes/messages.py @@ -13,8 +13,8 @@ class Message(object): self.col = getattr(loc, 'col_offset', 0) def __str__(self): - return '%s:%s: %s' % (self.filename, self.lineno, - self.message % self.message_args) + return '%s:%s:%s %s' % (self.filename, self.lineno, self.col+1, + self.message % self.message_args) class UnusedImport(Message): |