Skip to content

Commit

Permalink
Version 0011 (#113)
Browse files Browse the repository at this point in the history
* Version 0.0.11 prerelease

* Removes allowed failure
  • Loading branch information
sobolevn authored Sep 10, 2018
1 parent 93c580c commit 087f594
Show file tree
Hide file tree
Showing 9 changed files with 98 additions and 27 deletions.
4 changes: 0 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ matrix:
- python: 3.7
dist: xenial
sudo: true
allow_failures: # we allow failures because of `flake8` warning, it's a bug
- python: 3.7
dist: xenial
sudo: true

install:
- pip install poetry
Expand Down
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,22 @@
We follow Semantic Versions since the `0.1.0` release.


## Version 0.0.11

This is just a supporting release.
There are no new features introduced.

### Bugfixes

- Fixes [`python3.7` support](https://github.com/wemake-services/wemake-python-styleguide/issues/93)
- Fixes [`AttributeError: 'ExceptHandler' object has no attribute 'depth' `](https://github.com/wemake-services/wemake-python-styleguide/issues/112)

### Misc

- Introduced the concept of regression testing, see `test/fixtures/regression`
- Removed `compat.py`


## Version 0.0.10 aka The Module Reaper

### Features
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "wemake-python-styleguide"
version = "0.0.10"
version = "0.0.11"
description = "The most opinionated linter ever, used by wemake.services"

license = "MIT"
Expand Down
7 changes: 7 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,19 @@ flake8-ignore =
wemake_python_styleguide/visitors/ast/*.py N802
# These modules should contain a lot of classes:
wemake_python_styleguide/errors/*.py Z208
# Disable filename checks for regression testing:
tests/test_checkers/test_regression/*.py N999
# Disable some pydocstyle checks:
*.py D100 D104 D106 D401

# py.test options:
norecursedirs = tests/fixtures *.egg .eggs dist build docs .tox .git __pycache__

filterwarnings =
ignore::DeprecationWarning
ignore::PendingDeprecationWarning
ignore::FutureWarning

# You will need to measure your tests speed with `-n auto` and without it,
# so you can see whether it gives you any performance gain, or just gives
# you an overhead. See `docs/template/development-process.rst`.
Expand Down
27 changes: 27 additions & 0 deletions tests/fixtures/regression/issue112.py
Original file line number Diff line number Diff line change
@@ -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')
26 changes: 26 additions & 0 deletions tests/test_checkers/test_regression/test_issue112.py
Original file line number Diff line number Diff line change
@@ -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
21 changes: 20 additions & 1 deletion tests/test_visitors/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down
3 changes: 1 addition & 2 deletions wemake_python_styleguide/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
19 changes: 0 additions & 19 deletions wemake_python_styleguide/compat.py

This file was deleted.

0 comments on commit 087f594

Please sign in to comment.