myint: I still don't see anything wrong with this. I'll merge it.
diff --git a/pyflakes/checker.py b/pyflakes/checker.py
index baef833..9b39e6c 100644
--- a/pyflakes/checker.py
+++ b/pyflakes/checker.py
@@ -710,10 +710,14 @@ class Checker(object):
 
         # try enclosing function scopes and global scope
         for scope in self.scopeStack[-1::-1]:
-            # only generators used in a class scope can access the names
-            # of the class. this is skipped during the first iteration
-            if in_generators is False and isinstance(scope, ClassScope):
-                continue
+            if isinstance(scope, ClassScope):
+                if not PY2 and name == '__class__':
+                    return
+                elif in_generators is False:
+                    # only generators used in a class scope can access the
+                    # names of the class. this is skipped during the first
+                    # iteration
+                    continue
 
             try:
                 scope[name].used = (self.scope, node)

On Python 3, __class__ can be used without self
*Original report by [icordasc](https://launchpad.net/~icordasc) (@sigmavirus24?) on [Launchpad](https://bugs.launchpad.net/bugs/1487725):*

------------------------------------

On Python 3, the following code raises a warning:

```python
class Test(object):
    def __init__(self):
        print(__class__.__name__)
        self.x = 1

t = Test()
```

This is actually valid Python 3 code, but PyFlakes doesn't quite understand that:

    test.py:3: undefined name '__class__'

diff --git a/pyflakes/test/test_undefined_names.py b/pyflakes/test/test_undefined_names.py
index 3d19210..d53e529 100644
--- a/pyflakes/test/test_undefined_names.py
+++ b/pyflakes/test/test_undefined_names.py
@@ -799,6 +799,24 @@ class Test(TestCase):
         any(lambda: id(y) for x in range(10))
         ''', m.UndefinedName)
 
+    def test_dunderClass(self):
+        """
+        `__class__` is defined in class scope under Python 3, but is not
+        in Python 2.
+        """
+        code = '''
+        class Test(object):
+            def __init__(self):
+                print(__class__.__name__)
+                self.x = 1
+
+        t = Test()
+        '''
+        if version_info < (3,):
+            self.flakes(code, m.UndefinedName)
+        else:
+            self.flakes(code)
+
 
 class NameTests(TestCase):
     """

pip install -e .
parse_log_pytest
pytest
flake8 pep8 pytest
3.6
pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
attrs @ file:///opt/conda/conda-bld/attrs_1642510447205/work
certifi==2021.5.30
flake8==5.0.4
importlib-metadata==4.2.0
iniconfig @ file:///home/linux1/recipes/ci/iniconfig_1610983019677/work
mccabe==0.7.0
more-itertools @ file:///tmp/build/80754af9/more-itertools_1637733554872/work
packaging @ file:///tmp/build/80754af9/packaging_1637314298585/work
pep8==1.7.1
pluggy @ file:///tmp/build/80754af9/pluggy_1615976315926/work
py @ file:///opt/conda/conda-bld/py_1644396412707/work
pycodestyle==2.9.1
-e git+https://github.com/PyCQA/pyflakes.git@8a1feac08dae2478e3f67ab4018af86ff4ec56f0#egg=pyflakes
pyparsing @ file:///tmp/build/80754af9/pyparsing_1635766073266/work
pytest==6.2.4
toml @ file:///tmp/build/80754af9/toml_1616166611790/work
typing_extensions @ file:///opt/conda/conda-bld/typing_extensions_1647553014482/work
zipp @ file:///tmp/build/80754af9/zipp_1633618647012/work

name: pyflakes
channels:
  - defaults
  - https://repo.anaconda.com/pkgs/main
  - https://repo.anaconda.com/pkgs/r
  - conda-forge
dependencies:
  - _libgcc_mutex=0.1=main
  - _openmp_mutex=5.1=1_gnu
  - attrs=21.4.0=pyhd3eb1b0_0
  - ca-certificates=2025.2.25=h06a4308_0
  - certifi=2021.5.30=py36h06a4308_0
  - importlib_metadata=4.8.1=hd3eb1b0_0
  - iniconfig=1.1.1=pyhd3eb1b0_0
  - ld_impl_linux-64=2.40=h12ee557_0
  - libffi=3.3=he6710b0_2
  - libgcc-ng=11.2.0=h1234567_1
  - libgomp=11.2.0=h1234567_1
  - libstdcxx-ng=11.2.0=h1234567_1
  - more-itertools=8.12.0=pyhd3eb1b0_0
  - ncurses=6.4=h6a678d5_0
  - openssl=1.1.1w=h7f8727e_0
  - packaging=21.3=pyhd3eb1b0_0
  - pip=21.2.2=py36h06a4308_0
  - pluggy=0.13.1=py36h06a4308_0
  - py=1.11.0=pyhd3eb1b0_0
  - pyparsing=3.0.4=pyhd3eb1b0_0
  - pytest=6.2.4=py36h06a4308_2
  - python=3.6.13=h12debd9_1
  - readline=8.2=h5eee18b_0
  - setuptools=58.0.4=py36h06a4308_0
  - sqlite=3.45.3=h5eee18b_0
  - tk=8.6.14=h39e8969_0
  - toml=0.10.2=pyhd3eb1b0_0
  - typing_extensions=4.1.1=pyh06a4308_0
  - wheel=0.37.1=pyhd3eb1b0_0
  - xz=5.6.4=h5eee18b_1
  - zipp=3.6.0=pyhd3eb1b0_0
  - zlib=1.2.13=h5eee18b_1
  - pip:
      - flake8==5.0.4
      - importlib-metadata==4.2.0
      - mccabe==0.7.0
      - pep8==1.7.1
      - pycodestyle==2.9.1
prefix: /opt/conda/envs/pyflakes

pyflakes/test/test_undefined_names.py::Test::test_dunderClass
pyflakes/test/test_undefined_names.py::Test::test_annotationUndefined pyflakes/test/test_undefined_names.py::Test::test_badNestedClass pyflakes/test/test_undefined_names.py::Test::test_builtinWindowsError pyflakes/test/test_undefined_names.py::Test::test_builtins pyflakes/test/test_undefined_names.py::Test::test_definedAsStarArgs pyflakes/test/test_undefined_names.py::Test::test_definedAsStarUnpack pyflakes/test/test_undefined_names.py::Test::test_definedByGlobal pyflakes/test/test_undefined_names.py::Test::test_definedByGlobalMultipleNames pyflakes/test/test_undefined_names.py::Test::test_definedFromLambdaInDictionaryComprehension pyflakes/test/test_undefined_names.py::Test::test_definedFromLambdaInGenerator pyflakes/test/test_undefined_names.py::Test::test_definedInClass pyflakes/test/test_undefined_names.py::Test::test_definedInClassNested pyflakes/test/test_undefined_names.py::Test::test_definedInGenExp pyflakes/test/test_undefined_names.py::Test::test_definedInListComp pyflakes/test/test_undefined_names.py::Test::test_del pyflakes/test/test_undefined_names.py::Test::test_delConditional pyflakes/test/test_undefined_names.py::Test::test_delConditionalNested pyflakes/test/test_undefined_names.py::Test::test_delExceptionInExcept pyflakes/test/test_undefined_names.py::Test::test_delGlobal pyflakes/test/test_undefined_names.py::Test::test_delUndefined pyflakes/test/test_undefined_names.py::Test::test_delWhile pyflakes/test/test_undefined_names.py::Test::test_delWhileNested pyflakes/test/test_undefined_names.py::Test::test_delWhileTestUsage pyflakes/test/test_undefined_names.py::Test::test_doubleNestingReportsClosestName pyflakes/test/test_undefined_names.py::Test::test_functionsNeedGlobalScope pyflakes/test/test_undefined_names.py::Test::test_globalFromNestedScope pyflakes/test/test_undefined_names.py::Test::test_globalImportStar pyflakes/test/test_undefined_names.py::Test::test_globalInGlobalScope pyflakes/test/test_undefined_names.py::Test::test_global_reset_name_only pyflakes/test/test_undefined_names.py::Test::test_intermediateClassScopeIgnored pyflakes/test/test_undefined_names.py::Test::test_keywordOnlyArgs pyflakes/test/test_undefined_names.py::Test::test_keywordOnlyArgsUndefined pyflakes/test/test_undefined_names.py::Test::test_laterRedefinedGlobalFromNestedScope pyflakes/test/test_undefined_names.py::Test::test_laterRedefinedGlobalFromNestedScope2 pyflakes/test/test_undefined_names.py::Test::test_laterRedefinedGlobalFromNestedScope3 pyflakes/test/test_undefined_names.py::Test::test_magicGlobalsBuiltins pyflakes/test/test_undefined_names.py::Test::test_magicGlobalsFile pyflakes/test/test_undefined_names.py::Test::test_magicGlobalsName pyflakes/test/test_undefined_names.py::Test::test_magicGlobalsPath pyflakes/test/test_undefined_names.py::Test::test_metaClassUndefined pyflakes/test/test_undefined_names.py::Test::test_namesDeclaredInExceptBlocks pyflakes/test/test_undefined_names.py::Test::test_nestedClass pyflakes/test/test_undefined_names.py::Test::test_undefined pyflakes/test/test_undefined_names.py::Test::test_undefinedAugmentedAssignment pyflakes/test/test_undefined_names.py::Test::test_undefinedExceptionName pyflakes/test/test_undefined_names.py::Test::test_undefinedExceptionNameObscuringGlobalVariableFalsePositive1 pyflakes/test/test_undefined_names.py::Test::test_undefinedExceptionNameObscuringGlobalVariableFalsePositive2 pyflakes/test/test_undefined_names.py::Test::test_undefinedExceptionNameObscuringLocalVariable2 pyflakes/test/test_undefined_names.py::Test::test_undefinedExceptionNameObscuringLocalVariableFalsePositive1 pyflakes/test/test_undefined_names.py::Test::test_undefinedExceptionNameObscuringLocalVariableFalsePositive2 pyflakes/test/test_undefined_names.py::Test::test_undefinedFromLambdaInComprehension pyflakes/test/test_undefined_names.py::Test::test_undefinedFromLambdaInDictionaryComprehension pyflakes/test/test_undefined_names.py::Test::test_undefinedInGenExpNested pyflakes/test/test_undefined_names.py::Test::test_undefinedInListComp pyflakes/test/test_undefined_names.py::Test::test_undefinedInLoop pyflakes/test/test_undefined_names.py::Test::test_undefinedWithErrorHandler pyflakes/test/test_undefined_names.py::Test::test_unusedAsStarUnpack pyflakes/test/test_undefined_names.py::Test::test_usedAsStarUnpack pyflakes/test/test_undefined_names.py::NameTests::test_impossibleContext
pyflakes/checker.py
pyflakes/checker.py