Skip to content

Commit 48cf1eb

Browse files
authored
Merge pull request #8 from anikolaienko/feature/update-code-checking-tools
Update code checking tools and dev dependencies
2 parents d782925 + b986155 commit 48cf1eb

21 files changed

+312
-554
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,6 @@ dmypy.json
127127

128128
# Pyre type checker
129129
.pyre/
130+
131+
# Coming in future, but not yet
132+
sphinx-docs/

.pre-commit-config.yaml

Lines changed: 52 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,55 @@
11
# See https://pre-commit.com for more information
22
# See https://pre-commit.com/hooks.html for more hooks
3+
files: ".py$"
4+
exclude: "sphinx-docs/"
35
repos:
4-
- repo: local
5-
hooks:
6-
- id: black
7-
name: black
8-
description: "Black: The uncompromising Python code formatter"
9-
entry: black
10-
language: python
11-
require_serial: true
12-
types_or: [python, pyi]
13-
- id: flake8
14-
name: flake8
15-
description: '`flake8` is a command-line utility for enforcing style consistency across Python projects.'
16-
entry: flake8
17-
language: python
18-
types: [python]
19-
require_serial: true
20-
- id: mypy
21-
name: mypy
22-
description: 'Mypy is a static type checker for Python 3'
23-
entry: mypy
24-
language: python
25-
types: [python]
26-
require_serial: true
6+
- repo: https://github.com/psf/black
7+
rev: 22.10.0
8+
hooks:
9+
- id: black
10+
name: black
11+
description: "Black: The uncompromising Python code formatter"
12+
entry: black
13+
language: python
14+
require_serial: true
15+
types_or: [python, pyi]
16+
args: [--config=code-checks/.black.cfg]
17+
- repo: https://github.com/PyCQA/isort
18+
rev: 5.10.1
19+
hooks:
20+
- id: isort
21+
name: Run isort to sort imports in Python files
22+
files: \.py$|\.pyi$
23+
args: [--settings-path=code-checks/.isort.cfg]
24+
- repo: https://github.com/pre-commit/pre-commit-hooks
25+
rev: v4.3.0
26+
hooks:
27+
- id: check-merge-conflict
28+
name: Check that merge conflicts are not being committed
29+
- id: trailing-whitespace
30+
name: Remove trailing whitespace at end of line
31+
- id: mixed-line-ending
32+
name: Detect if mixed line ending is used (\r vs. \r\n)
33+
- id: end-of-file-fixer
34+
name: Make sure that there is an empty line at the end
35+
- repo: https://github.com/PyCQA/flake8
36+
rev: 5.0.4
37+
hooks:
38+
- id: flake8
39+
name: flake8
40+
description: '`flake8` is a command-line utility for enforcing style consistency across Python projects.'
41+
entry: flake8
42+
language: python
43+
types: [python]
44+
require_serial: true
45+
args: [--config=code-checks/.flake8]
46+
- repo: local
47+
hooks:
48+
- id: mypy
49+
name: mypy
50+
description: 'Optional static typing for Python (installed by Poetry)'
51+
entry: mypy
52+
language: python
53+
require_serial: true
54+
types_or: [python, pyi]
55+
args: [--config-file=code-checks/.mypy.ini]

automapper/__init__.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
# flake8: noqa: F401
2-
from .mapper import Mapper
3-
42
from .exceptions import (
3+
CircularReferenceError,
54
DuplicatedRegistrationError,
65
MappingError,
7-
CircularReferenceError,
86
)
9-
7+
from .mapper import Mapper
108
from .mapper_initializer import create_mapper
119

1210
# Global mapper

automapper/extensions/default.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
from typing import Type, TypeVar, Iterable
1+
from typing import Iterable, Type, TypeVar
22

33
from automapper import Mapper
44

5-
65
T = TypeVar("T")
76
_IGNORED_FIELDS = ("return", "args", "kwargs")
87

automapper/extensions/pydantic.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
from typing import Type, Iterable
2-
3-
from pydantic import BaseModel
1+
from typing import Iterable, Type
42

53
from automapper import Mapper
4+
from pydantic import BaseModel
65

76

87
def spec_function(target_cls: Type[BaseModel]) -> Iterable[str]:

automapper/extensions/sqlalchemy.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
from sqlalchemy import inspect
2-
3-
from typing import Type, Iterable
1+
from typing import Iterable, Type
42

53
from automapper import Mapper
4+
from sqlalchemy import inspect
65

76

87
def sqlalchemy_spec_decide(obj_type: Type[object]) -> bool:

automapper/extensions/tortoise.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
from typing import Type, Iterable
2-
3-
from tortoise import Model
1+
from typing import Iterable, Type
42

53
from automapper import Mapper
4+
from tortoise import Model
65

76

87
def spec_function(target_cls: Type[Model]) -> Iterable[str]:

automapper/mapper.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1+
import inspect
2+
from copy import deepcopy
13
from typing import (
24
Any,
5+
Callable,
6+
Dict,
7+
Generic,
8+
Iterable,
39
Optional,
10+
Set,
411
Tuple,
5-
Union,
612
Type,
713
TypeVar,
8-
Dict,
9-
Set,
10-
Callable,
11-
Iterable,
12-
Generic,
13-
overload,
14+
Union,
1415
cast,
16+
overload,
1517
)
16-
from copy import deepcopy
17-
import inspect
1818

1919
from .exceptions import (
2020
CircularReferenceError,
@@ -165,7 +165,7 @@ def map(
165165
*,
166166
skip_none_values: bool = False,
167167
fields_mapping: FieldsMap = None,
168-
) -> T:
168+
) -> T: # type: ignore [type-var]
169169
"""Produces output object mapped from source object and custom arguments"""
170170
obj_type = type(obj)
171171
if obj_type not in self._mappings:
@@ -301,7 +301,7 @@ def _map_common(
301301

302302
_visited_stack.remove(obj_id)
303303

304-
return cast(target_cls, target_cls(**mapped_values)) # type: ignore [call-arg, redundant-cast, valid-type]
304+
return cast(target_cls, target_cls(**mapped_values)) # type: ignore [valid-type]
305305

306306
def to(self, target_cls: Type[T]) -> MappingWrapper[T]:
307307
"""Specify target class to map source object to"""

automapper/mapper_initializer.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
from os.path import dirname, join, isfile, basename
2-
import logging
1+
import glob
32
import importlib
43
import importlib.util
5-
import glob
4+
import logging
5+
from os.path import basename, dirname, isfile, join
66

77
from . import Mapper
88

@@ -28,7 +28,7 @@ def create_mapper() -> Mapper:
2828
extension_package = importlib.import_module(
2929
__PACKAGE_PATH__ + "." + module_name
3030
)
31-
extension_package.extend(mapper) # type: ignore [attr-defined]
31+
extension_package.extend(mapper)
3232
except Exception:
3333
log.exception(
3434
f"Found module {module_name} but could not load extension for it."

code-checks/.black.cfg

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[black]
2+
line-length = 120
3+
target-version = ['py38']
4+
include = '\.pyi?$'

0 commit comments

Comments
 (0)