Repository: ikasymov/fastapi-localization (language: python)

Issue:
flake8, mypy
add some linters and static type checker like flake8 and mypy.


Discussion / hints:

Fix patch:
diff --git a/.flake8 b/.flake8
new file mode 100644
index 0000000..3f01338
--- /dev/null
+++ b/.flake8
@@ -0,0 +1,18 @@
+[flake8]
+per-file-ignores =
+    # imported but unused
+    __init__.py: F401
+
+ignore =
+    # A003 class attribute "id" is shadowing a python builtin
+    A003,
+
+    # C408 Unnecessary dict call - rewrite as a literal.
+    C408,
+
+max-line-length = 120
+exclude =
+    .git,
+    __pycache__,
+    */tests/*,
+    venv/*,
diff --git a/.isort.cfg b/.isort.cfg
new file mode 100644
index 0000000..2eb88fc
--- /dev/null
+++ b/.isort.cfg
@@ -0,0 +1,35 @@
+[settings]
+
+# Global
+multi_line_output=3
+include_trailing_comma=True
+line_length=120
+lines_after_imports=2
+lines_between_sections=1
+lines_between_types=0
+force_alphabetical_sort_within_sections=True
+ensure_newline_before_comments=True
+combine_as_imports=True
+combine_star=True
+skip_gitignore=True
+balanced_wrapping=True
+force_grid_wrap=2
+
+# Local
+src_paths=
+    fastapi_localization
+    tests
+
+skip_glob=
+    .git
+    .idea
+    .vscode
+
+
+# Sections
+sections=
+    FUTURE,
+    STDLIB,
+    THIRDPARTY,
+    FIRSTPARTY,
+    LOCALFOLDER
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
new file mode 100644
index 0000000..56d3404
--- /dev/null
+++ b/.pre-commit-config.yaml
@@ -0,0 +1,116 @@
+default_language_version:
+    python: python3.7
+
+
+default_stages: [commit, push]
+
+
+repos:
+  - repo: https://github.com/pre-commit/pre-commit-hooks
+    rev: v3.4.0
+    hooks:
+      - id: check-ast
+      - id: check-case-conflict
+      - id: check-json
+      - id: check-toml
+      - id: check-merge-conflict
+      - id: debug-statements
+      - id: end-of-file-fixer
+      - id: pretty-format-json
+        args: [
+          --autofix,
+          --indent 4,
+        ]
+      - id: trailing-whitespace
+      - id: no-commit-to-branch
+        args: [
+          --branch, develop,
+          --branch, master,
+        ]
+
+  - repo: https://github.com/asottile/pyupgrade
+    rev: v2.11.0
+    hooks:
+      - id: pyupgrade
+        args: [--py38-plus]
+
+  - repo: https://github.com/myint/autoflake
+    rev: v1.4
+    hooks:
+      - id: autoflake
+        args: [
+            --in-place,
+            --remove-all-unused-imports,
+            --ignore-init-module-imports,
+            --remove-unused-variables,
+        ]
+
+  - repo: https://github.com/pre-commit/mirrors-autopep8
+    rev: v1.5.6
+    hooks:
+      - id: autopep8
+        args: [
+          --global-config=.flake8,
+          --in-place,
+        ]
+
+  - repo: https://github.com/timothycrosley/isort
+    rev: 5.8.0
+    hooks:
+      - id: isort
+        name: Isort
+        additional_dependencies: [toml]
+        exclude: ^.*/?setup\.py$
+        args: [
+          --sp=.isort.cfg,
+        ]
+        stages:
+          - commit
+        verbose: True
+
+  - repo: https://github.com/asottile/add-trailing-comma
+    rev: v2.1.0
+    hooks:
+      - id: add-trailing-comma
+        args: [--py36-plus]
+        stages:
+          - commit
+
+  - repo: https://github.com/asottile/yesqa
+    rev: v1.2.2
+    hooks:
+      - id: yesqa
+        additional_dependencies:
+          - flake8==3.9.0
+          - flake8-builtins==1.5.3
+          - flake8-commas==2.0.0
+          - flake8-debugger==4.0.0
+          - flake8-comprehensions==3.3.1
+          - flake8-eradicate==1.0.0
+          - dlint==0.11.0
+
+  - repo: https://gitlab.com/pycqa/flake8
+    rev: 3.9.0
+    hooks:
+      - id: flake8
+        args: [
+          --config=.flake8,
+          --max-line-length=120,
+        ]
+        exclude: .git|__pycache__
+        additional_dependencies:
+          - flake8-builtins==1.5.3
+          - flake8-commas==2.0.0
+          - flake8-debugger==4.0.0
+          - flake8-comprehensions==3.3.1
+          - flake8-eradicate==1.0.0
+          - dlint==0.11.0
+
+  - repo: https://github.com/milin/giticket
+    rev: v1.1
+    hooks:
+      - id: giticket
+        args: [
+          '--regex=[A-Za-z]+-\d+',
+          '--format=[{ticket}] {commit_msg}',
+        ]
diff --git a/fastapi_localization/__init__.py b/fastapi_localization/__init__.py
index 1d441a9..322115d 100644
--- a/fastapi_localization/__init__.py
+++ b/fastapi_localization/__init__.py
@@ -1,19 +1,21 @@
-from fastapi_localization.middleware import SystemLocalizationMiddleware
 from fastapi_localization.exception_handlers import (
     http_exception_handler,
-    validation_exception_handler
+    validation_exception_handler,
 )
-from fastapi_localization.route import LocalizationRoute
-from fastapi_localization.response import TranslateJsonResponse
 from fastapi_localization.localization import (
     lazy_gettext,
     LazyString,
-    TranslatableStringField
+    TranslatableStringField,
 )
+from fastapi_localization.middleware import SystemLocalizationMiddleware
+from fastapi_localization.response import TranslateJsonResponse
+from fastapi_localization.route import LocalizationRoute
+
+
 __all__ = ["SystemLocalizationMiddleware", "http_exception_handler",
            "validation_exception_handler", "LocalizationRoute",
            "TranslateJsonResponse", "lazy_gettext",
            "LazyString", "TranslatableStringField"]
 
 
-__version__ = '0.0a1.dev3'
+__version__ = '0.0a2.dev3'
diff --git a/fastapi_localization/exception_handlers.py b/fastapi_localization/exception_handlers.py
index acd3592..e2985fd 100644
--- a/fastapi_localization/exception_handlers.py
+++ b/fastapi_localization/exception_handlers.py
@@ -4,8 +4,8 @@
 )
 from fastapi.exceptions import RequestValidationError
 
-from fastapi_localization.response import TranslateJsonResponse
 from fastapi_localization.localization import lazy_gettext
+from fastapi_localization.response import TranslateJsonResponse
 
 
 async def http_exception_handler(request, exc: HTTPException):
diff --git a/fastapi_localization/response.py b/fastapi_localization/response.py
index 92729a5..01557c3 100644
--- a/fastapi_localization/response.py
+++ b/fastapi_localization/response.py
@@ -1,5 +1,5 @@
-import typing
 import gettext
+import typing
 
 from fastapi.responses import JSONResponse
 
diff --git a/fastapi_localization/route.py b/fastapi_localization/route.py
index 61012ae..0cbfa87 100644
--- a/fastapi_localization/route.py
+++ b/fastapi_localization/route.py
@@ -1,7 +1,10 @@
 from typing import Callable
 
+from fastapi import (
+    Request,
+    Response,
+)
 from fastapi.routing import APIRoute
-from fastapi import Request, Response
 
 from fastapi_localization.response import TranslateJsonResponse
 
diff --git a/requirements-dev.txt b/requirements-dev.txt
index 0703bf4..f0ea662 100644
--- a/requirements-dev.txt
+++ b/requirements-dev.txt
@@ -2,4 +2,8 @@
 
 pytest==6.2.1
 requests==2.25.1
-pytest-asyncio==0.14.0
\ No newline at end of file
+pytest-asyncio==0.14.0
+mypy==0.902
+isort==5.8.0
+flake8==3.9.2
+pre-commit
diff --git a/setup.py b/setup.py
index e89de5f..8cbd311 100644
--- a/setup.py
+++ b/setup.py
@@ -1,6 +1,6 @@
 from setuptools import (
-      setup,
-      find_packages,
+    find_packages,
+    setup,
 )
 
 import fastapi_localization


Test patch:
diff --git a/tests/test_exception_handlers.py b/tests/test_exception_handlers.py
index dc7eff5..f337a4d 100644
--- a/tests/test_exception_handlers.py
+++ b/tests/test_exception_handlers.py
@@ -11,7 +11,7 @@
 
 from fastapi_localization.exception_handlers import (
     http_exception_handler,
-    validation_exception_handler
+    validation_exception_handler,
 )
 from fastapi_localization.localization import lazy_gettext
 
diff --git a/tests/test_localization.py b/tests/test_localization.py
index d748d9e..611089c 100644
--- a/tests/test_localization.py
+++ b/tests/test_localization.py
@@ -1,12 +1,13 @@
 from unittest.mock import MagicMock
 
 from fastapi_localization.localization import (
+    lazy_gettext,
     LazyString,
-    TranslatableStringField,
     prepare_content_to_translate,
-    lazy_gettext
+    TranslatableStringField,
 )
 
+
 my_string = 'my message'
 username = 'SomeUser'
 
diff --git a/tests/test_route.py b/tests/test_route.py
index d9c2270..708656e 100644
--- a/tests/test_route.py
+++ b/tests/test_route.py
@@ -1,12 +1,14 @@
 import json
+
 from fastapi import FastAPI
 from fastapi.testclient import TestClient
 from starlette.middleware.base import BaseHTTPMiddleware
 
 from fastapi_localization import SystemLocalizationMiddleware
-from fastapi_localization.route import LocalizationRoute
-from fastapi_localization.response import TranslateJsonResponse
 from fastapi_localization.localization import lazy_gettext as _
+from fastapi_localization.response import TranslateJsonResponse
+from fastapi_localization.route import LocalizationRoute
+
 
 app = FastAPI()
 client = TestClient(app)