Repository: PyCQA/pyflakes

Issue:
Class-level `TypeVar` resulting in "undefined name" error
Minimal sample:
```
from typing import TypeVar


class IdClass:
    Y = TypeVar('Y')

    def id(self, x: Y) -> Y:
        return x
```
Result:
```
# pyflakes t.py 
t.py:7: undefined name 'Y'
```

MyPy supports such typing annotations and does not complain about this file.
Probably this issue is related to similar ones #427 and #126 

Discussion:

Patch:
diff --git a/pyflakes/checker.py b/pyflakes/checker.py
index 0e636c1..83f92aa 100644
--- a/pyflakes/checker.py
+++ b/pyflakes/checker.py
@@ -1480,7 +1480,7 @@ class Checker(object):
 
             self.pushScope()
 
-            self.handleChildren(node, omit='decorator_list')
+            self.handleChildren(node, omit=['decorator_list', 'returns'])
 
             def checkUnusedAssignments():
                 """


Test patch:
diff --git a/pyflakes/test/test_type_annotations.py b/pyflakes/test/test_type_annotations.py
index 03f70bb..9c34dcf 100644
--- a/pyflakes/test/test_type_annotations.py
+++ b/pyflakes/test/test_type_annotations.py
@@ -342,3 +342,23 @@ class TestTypeAnnotations(TestCase):
         x = 1
         # type: F
         """)
+
+    @skipIf(version_info < (3,), 'new in Python 3')
+    def test_return_annotation_is_class_scope_variable(self):
+        self.flakes("""
+        from typing import TypeVar
+        class Test:
+            Y = TypeVar('Y')
+
+            def t(self, x: Y) -> Y:
+                return x
+        """)
+
+    @skipIf(version_info < (3,), 'new in Python 3')
+    def test_return_annotation_is_function_body_variable(self):
+        self.flakes("""
+        class Test:
+            def t(self) -> Y:
+                Y = 2
+                return Y
+        """, m.UndefinedName)