Repository: PyCQA/pyflakes

Issue:
Incorrect line number for syntax error in type comment
Minor issue, pyflakes 2.1.0 (macOS High Sierra and Ubuntu Xenial) is reporting an issue at line 196 when it's really at line 208. Pyflakes 2.0.0 did not report the issue at all.

To reproduce:

```console
$ pip install -U pyflakes
Requirement already up-to-date: pyflakes in /usr/local/lib/python3.7/site-packages (2.1.0)
$ wget https://raw.githubusercontent.com/python-pillow/Pillow/a656a0bd603bcc333184ad1baf61d118925b3772/Tests/test_file_libtiff.py
--2019-01-30 11:03:02--  https://raw.githubusercontent.com/python-pillow/Pillow/a656a0bd603bcc333184ad1baf61d118925b3772/Tests/test_file_libtiff.py
Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 151.101.244.133
Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|151.101.244.133|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 23915 (23K) [text/plain]
Saving to: ‘test_file_libtiff.py’

test_file_libtiff.py               100%[==============================================================>]  23.35K  --.-KB/s    in 0.001s

2019-01-30 11:03:02 (15.9 MB/s) - ‘test_file_libtiff.py’ saved [23915/23915]

$ pyflakes test_file_libtiff.py
test_file_libtiff.py:196: syntax error in type comment 'dummy value'
$ grep --line-number "dummy value" test_file_libtiff.py
208:        # type: dummy value
```

File on GitHub:

https://github.com/python-pillow/Pillow/blob/a656a0bd603bcc333184ad1baf61d118925b3772/Tests/test_file_libtiff.py#L208


Discussion:
sigmavirus24: Closing/re-opening in the hopes it triggers a new merge on AppVeyor
asottile: Rebased and this is passing now :tada: 

Patch:
diff --git a/pyflakes/checker.py b/pyflakes/checker.py
index 70aaff2..4c88af2 100644
--- a/pyflakes/checker.py
+++ b/pyflakes/checker.py
@@ -507,6 +507,13 @@ class DoctestScope(ModuleScope):
     """Scope for a doctest."""
 
 
+class DummyNode(object):
+    """Used in place of an `ast.AST` to set error message positions"""
+    def __init__(self, lineno, col_offset):
+        self.lineno = lineno
+        self.col_offset = col_offset
+
+
 # Globally defined names which are not attributes of the builtins module, or
 # are only present on some platforms.
 _MAGIC_GLOBALS = ['__file__', '__builtins__', 'WindowsError']
@@ -1056,7 +1063,7 @@ class Checker(object):
                     part = part.replace('...', 'Ellipsis')
                 self.deferFunction(functools.partial(
                     self.handleStringAnnotation,
-                    part, node, lineno, col_offset,
+                    part, DummyNode(lineno, col_offset), lineno, col_offset,
                     messages.CommentAnnotationSyntaxError,
                 ))
 


Test patch:
diff --git a/pyflakes/test/test_type_annotations.py b/pyflakes/test/test_type_annotations.py
index 5af4441..48635bb 100644
--- a/pyflakes/test/test_type_annotations.py
+++ b/pyflakes/test/test_type_annotations.py
@@ -297,6 +297,13 @@ class TestTypeAnnotations(TestCase):
             pass
         """, m.CommentAnnotationSyntaxError)
 
+    def test_typeCommentsSyntaxErrorCorrectLine(self):
+        checker = self.flakes("""\
+        x = 1
+        # type: definitely not a PEP 484 comment
+        """, m.CommentAnnotationSyntaxError)
+        self.assertEqual(checker.messages[0].lineno, 2)
+
     def test_typeCommentsAssignedToPreviousNode(self):
         # This test demonstrates an issue in the implementation which
         # associates the type comment with a node above it, however the type