Skip to content

Commit

Permalink
refactor imports' node validators
Browse files Browse the repository at this point in the history
  • Loading branch information
skarzi committed Jan 22, 2020
1 parent f8dc24e commit e48fcfa
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions wemake_python_styleguide/visitors/ast/imports.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
# -*- coding: utf-8 -*-

import abc
import ast
from itertools import chain
from typing import Callable, Iterable, cast
from typing import Callable, Iterable

from typing_extensions import final

Expand All @@ -29,7 +28,7 @@
ErrorCallback = Callable[[BaseViolation], None] # TODO: alias and move


class _BaseImportValidator(abc.ABC):
class _BaseImportValidator(object):
"""Base utility class to separate logic from the visitor."""

def __init__(
Expand All @@ -40,8 +39,7 @@ def __init__(
self._error_callback = error_callback
self._options = options

@abc.abstractmethod
def validate(self, node: AnyImport):
def _validate_any_import(self, node: AnyImport) -> None:
self._check_nested_import(node)
self._check_alias(node)
self._check_same_alias(node)
Expand Down Expand Up @@ -74,9 +72,8 @@ def _check_same_alias(self, node: AnyImport) -> None:
class _ImportValidator(_BaseImportValidator):
"""Validator of ``ast.Import`` nodes."""

def validate(self, node: AnyImport) -> None:
node = cast(ast.Import, node)
super().validate(node)
def validate(self, node: ast.Import) -> None:
self._validate_any_import(node)
self._check_dotted_raw_import(node)
self._check_protected_import(node)

Expand All @@ -100,9 +97,8 @@ def _check_protected_import(self, node: ast.Import) -> None:
class _ImportFromValidator(_BaseImportValidator):
"""Validator of ``ast.ImportFrom`` nodes."""

def validate(self, node: AnyImport) -> None:
node = cast(ast.ImportFrom, node)
super().validate(node)
def validate(self, node: ast.ImportFrom) -> None:
self._validate_any_import(node)
self._check_from_import(node)
self._check_protected_import_from_module(node)
self._check_protected_import_from_members(node)
Expand Down

0 comments on commit e48fcfa

Please sign in to comment.