Автоматическая проверка кода для Python работает некорректно - PullRequest
0 голосов
/ 18 января 2019

Я пытаюсь проверить свой код, используя специальную конфигурацию .pre фиксации-config.yaml РЕПО:

  • репо: https://github.com/ambv/black rev: «стабильный» Крючки:

    • id: черный args: [--py36, --line-length = 120, src / webhook_app] python-версия: python3.6
  • РЕПО: https://github.com/pre-commit/mirrors-mypy рев: v0.630 Крючки:

    • id: mypy args: [--no-строго-необязательный, --ignore-missing-import]
  • репо: https://github.com/pre-commit/pygrep-hooks версия v1.1.0 Крючки:

    • id: python-use-type-annotations
  • репо: https://github.com/pre-commit/mirrors-pylint версия v1.9.1 Крючки:

    • id: pylint
        args: [
          --max-line-length=120,
          --disable=design,
          --disable=missing-docstring,
          --disable=bad-continuation,
          --disable=max-module-lines,
          --disable=useless-super-delegation,
          --disable=import-error,
          --disable=logging-fstring-interpolation,
          --disable=invalid-name,
          --disable=duplicate-code
        ]
        # exclude tests folder and manage.py to be checked
        exclude: 'tests|manage.py'```
    
  • репо: https://github.com/pre-commit/pre-commit-hooks версия v1.4.0 Крючки:

    • id: flake8 args: ['--max-line-length = 120']
    • id: конечный пробел

Я начинаю проверку мой код

import warnings
from contextlib import contextmanager
from enum import Enum

from sqlalchemy import create_engine
from sqlalchemy import exc
from sqlalchemy.ext.declarative import DeferredReflection, declarative_base
from sqlalchemy.inspection import inspect
from sqlalchemy.orm import scoped_session, sessionmaker

import structlog


logger = structlog.get_logger(__name__)


class Base(DeferredReflection, declarative_base()): # type: ignore

    """ Abstract base class for construction of mappings
    based on a deferred reflection step.
    All classes inherited from it will be reflected by the time
    of calling DeferredReflection.prepare()""" 

    __abstract__ = True

    def __repr__(self):
        inspector = inspect(self.__table__)
        return "{}({})".format(
            self.__class__.__name__,
            ", ".join("%s=%s" % (column.name, self.__dict__[column.name]) for column in inspector.columns),
        )

Я получил ошибку от hookid: python-use-type-annotations

src/webhook_app/models.py:17:class Base(DeferredReflection, declarative_base()):  # type: ignore

Когда я удаляю # type: ignore python-use-type-annotations говорит, что все в порядке, но mypy отправляет мне ошибку Invalid base class.

Не могли бы вы мне помочь?

1 Ответ

0 голосов
/ 18 января 2019

Я думаю, вы не используете declarative_base() правильно.

Base = declarative_base(cls=DeferredReflection)

class MyClass(Base):
    ...

или

Base = declarative_base()

class MyClass(DeferredReflection, Base):
    ...
...