Repository: wemake-services/wemake-python-styleguide

Issue:
`python3.7` raises `flake8` warning
It is a bug in `flake8`:
- https://github.com/PyCQA/pycodestyle/issues/728

We currently allow `python3.7` build to fail.

```
=============================== warnings summary ===============================
tests/test_visitors/test_wrong_class/test_base_class.py::FLAKE8
  /home/travis/virtualenv/python3.7.0/lib/python3.7/site-packages/pycodestyle.py:113: FutureWarning: Possible nested set at position 1
    EXTRANEOUS_WHITESPACE_REGEX = re.compile(r'[[({] | []}),;:]')
-- Docs: https://docs.pytest.org/en/latest/warnings.html
=================== 1514 passed, 1 warnings in 27.96 seconds ===================
```


Discussion:
We will just ignore this warning for now.

Resolving patch:
diff --git a/wemake_python_styleguide/checker.py b/wemake_python_styleguide/checker.py
--- a/wemake_python_styleguide/checker.py
+++ b/wemake_python_styleguide/checker.py
@@ -6,7 +6,6 @@
 from flake8.options.manager import OptionManager
 
 from wemake_python_styleguide import constants
-from wemake_python_styleguide.compat import maybe_set_parent
 from wemake_python_styleguide.options.config import Configuration
 from wemake_python_styleguide.types import (
     CheckerSequence,
@@ -93,7 +92,7 @@ class Checker(object):
 
     def __init__(self, tree: Module, filename: str = constants.STDIN) -> None:
         """Creates new checker instance."""
-        self.tree = maybe_set_parent(tree)
+        self.tree = tree
         self.filename = filename
 
     @classmethod
diff --git a/wemake_python_styleguide/compat.py b/wemake_python_styleguide/compat.py
deleted file mode 100644
--- a/wemake_python_styleguide/compat.py
+++ /dev/null
@@ -1,19 +0,0 @@
-# -*- coding: utf-8 -*-
-
-"""
-This module contains ugly hacks and fixes for version compat issues.
-
-Do not be over-exited to add anything here.
-"""
-
-import ast
-
-
-def maybe_set_parent(tree: ast.AST) -> ast.AST:
-    """Sets parents for all nodes that do not have this prop."""
-    for statement in ast.walk(tree):
-        for child in ast.iter_child_nodes(statement):
-            if not hasattr(child, 'parent'):  # noqa: Z113
-                setattr(child, 'parent', statement)
-
-    return tree


Test patch:
diff --git a/tests/fixtures/regression/issue112.py b/tests/fixtures/regression/issue112.py
new file mode 100644
--- /dev/null
+++ b/tests/fixtures/regression/issue112.py
@@ -0,0 +1,27 @@
+# -*- coding: utf-8 -*-
+
+from server.logics.exceptions import AuthenticationException
+from server.models import ApplicationUser, TelegramSession
+
+
+def current_session(
+    telegram_id: int,
+    for_update: bool = True,
+) -> TelegramSession:
+    """
+    Was triggering `AttributeError`.
+
+    See: https://github.com/wemake-services/wemake-python-styleguide/issues/112
+    """
+    try:
+        query = TelegramSession.objects.all()
+        if for_update:  # Try to comment this `if` to fix everything
+            query = query.select_for_update()
+
+        return query.get(
+            uid=telegram_id,
+            is_verified=True,
+        )
+
+    except TelegramSession.DoesNotExist:
+        raise AuthenticationException('Session is missing')
diff --git a/tests/test_checkers/test_regression/test_issue112.py b/tests/test_checkers/test_regression/test_issue112.py
new file mode 100644
--- /dev/null
+++ b/tests/test_checkers/test_regression/test_issue112.py
@@ -0,0 +1,26 @@
+# -*- coding: utf-8 -*-
+
+import subprocess
+
+
+def test_regression_122(absolute_path):
+    """
+    For some reason there was an issue with `compat.py`.
+
+    When installing this package via `pip` there was an issue with
+    `ast` parsing. But, after moving `compat.py` to tests only,
+    the issue seems to be gone.
+
+    Conclusion: do not touch something that is working!
+
+    See: https://github.com/wemake-services/wemake-python-styleguide/issues/112
+    """
+    fixture = absolute_path('fixtures', 'regression', 'issue112.py')
+    process = subprocess.Popen(
+        ['flake8', '--select', 'Z', fixture],
+        stdout=subprocess.PIPE,
+        stderr=subprocess.PIPE,
+    )
+    stdout, _ = process.communicate()
+
+    assert stdout.count(b'Z') == 0
diff --git a/tests/test_visitors/conftest.py b/tests/test_visitors/conftest.py
--- a/tests/test_visitors/conftest.py
+++ b/tests/test_visitors/conftest.py
@@ -7,11 +7,30 @@
 
 import pytest
 
-from wemake_python_styleguide.compat import maybe_set_parent
 from wemake_python_styleguide.options import defaults
 from wemake_python_styleguide.visitors.base import BaseNodeVisitor
 
 
+def maybe_set_parent(tree: ast.AST) -> ast.AST:
+    """
+    Sets parents for all nodes that do not have this prop.
+
+    This step is required due to how `flake8` works.
+    It does not set the same properties as `ast` module.
+
+    This function was the cause of `issue-112`.
+
+    Version changed: 0.0.11
+
+    """
+    for statement in ast.walk(tree):
+        for child in ast.iter_child_nodes(statement):
+            if not hasattr(child, 'parent'):  # noqa: Z113
+                setattr(child, 'parent', statement)
+
+    return tree
+
+
 @pytest.fixture(scope='session')
 def parse_ast_tree():
     """Helper function to convert code to ast."""