Skip to content

Commit 6466da5

Browse files
committed
fixed mypy and flake8
1 parent 7877946 commit 6466da5

File tree

10 files changed

+31
-20
lines changed

10 files changed

+31
-20
lines changed

.code_quality/.flake8

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ max-line-length = 120
33
per-file-ignores =
44
**/__init__.py:F401,F403
55
ignore =
6-
E203 ; https://black.readthedocs.io/en/stable/the_black_code_style/current_style.html#slices
7-
W503 ; https://github.com/psf/black/issues/52
6+
; E203 whitespace before ':'
7+
E203
8+
; W503 line break before binary operator
9+
W503
10+
; E704 multiple statements on one line
11+
E704
812
count = True

.code_quality/.mypy.ini

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
[mypy]
2-
plugins = sqlalchemy.ext.mypy.plugin
3-
42
disallow_any_generics = True
53
disallow_subclassing_any = True
64
disallow_untyped_calls = True

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
2+
2.0.0 - 2024/05/12
3+
* Moved away from poetry. Changed packaging system using pip, build and twine.
4+
* Upgraded all dependencies.
5+
* Add support for Python 3.12.
6+
* Migrated SQLAlchemy from 1.x to 2.x.
7+
18
1.2.3 - 2022/11/21
29
* Added automated code checks for different Python versions.
310

automapper/extensions/sqlalchemy.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
from typing import Iterable, Type
22

33
from automapper import Mapper
4-
from sqlalchemy import inspect
4+
from sqlalchemy.inspection import inspect
5+
from sqlalchemy.orm import DeclarativeBase
56

67

78
def sqlalchemy_spec_decide(obj_type: Type[object]) -> bool:
89
return inspect(obj_type, raiseerr=False) is not None
910

1011

11-
def spec_function(target_cls: Type[object]) -> Iterable[str]:
12+
def spec_function(target_cls: Type[DeclarativeBase]) -> Iterable[str]:
1213
inspector = inspect(target_cls)
1314
attrs = [x.key for x in inspector.attrs]
1415
return attrs

automapper/mapper.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -233,10 +233,12 @@ def map(
233233
if target_cls_field_mappings:
234234
# transform mapping if it's from source class field
235235
common_fields_mapping = {
236-
target_obj_field: getattr(obj, source_field[len(obj_type_prefix) :])
237-
if isinstance(source_field, str)
238-
and source_field.startswith(obj_type_prefix)
239-
else source_field
236+
target_obj_field: (
237+
getattr(obj, source_field[len(obj_type_prefix) :])
238+
if isinstance(source_field, str)
239+
and source_field.startswith(obj_type_prefix)
240+
else source_field
241+
)
240242
for target_obj_field, source_field in target_cls_field_mappings.items()
241243
}
242244
if fields_mapping:

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "py-automapper"
7-
version = "1.2.3"
7+
version = "2.0.0"
88
description = "Library for automatically mapping one object to another"
99
authors = [
1010
{name = "Andrii Nikolaienko", email = "[email protected]"}
@@ -43,7 +43,7 @@ Changelog = "https://github.com/anikolaienko/py-automapper/blob/main/CHANGELOG.m
4343
dev = [
4444
"tortoise-orm~=0.20.1",
4545
"pydantic~=2.7.1",
46-
"SQLAlchemy[mypy]~=2.0.30",
46+
"SQLAlchemy~=2.0.30",
4747
"twine~=5.0.0",
4848
"Sphinx~=7.1.2"
4949
]

tests/extensions/test_default_extention.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ def fields(cls) -> Iterable[str]:
1919

2020
@runtime_checkable
2121
class ClassWithFieldsMethodProtocol(Protocol):
22-
def fields(self) -> Iterable[str]:
23-
...
22+
def fields(self) -> Iterable[str]: ...
2423

2524

2625
def classifier_func(target_cls: Type[T]) -> bool:

tests/extensions/test_sqlalchemy_extention.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44
from automapper import Mapper, MappingError
55
from automapper import mapper as default_mapper
66
from sqlalchemy import Column, Integer, String
7-
from sqlalchemy.orm import declarative_base
7+
from sqlalchemy.orm import DeclarativeBase
88

9-
Base = declarative_base()
9+
10+
class Base(DeclarativeBase):
11+
pass
1012

1113

1214
class UserInfo(Base):

tests/test_complex_objects_mapping.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ def fields(cls) -> Iterable[str]:
4141

4242

4343
class ClassWithFieldsMethodProtocol(Protocol):
44-
def fields(self) -> Iterable[str]:
45-
...
44+
def fields(self) -> Iterable[str]: ...
4645

4746

4847
class ComplexClass:

tests/test_predefined_mapping.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ def fields(cls) -> Iterable[str]:
4141

4242

4343
class ClassWithFieldsMethodProtocol(Protocol):
44-
def fields(self) -> Iterable[str]:
45-
...
44+
def fields(self) -> Iterable[str]: ...
4645

4746

4847
def custom_spec_func(concrete_class: Type[T]) -> Iterable[str]:

0 commit comments

Comments
 (0)