universal-mapper 1.0.1__tar.gz → 1.0.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {universal_mapper-1.0.1 → universal_mapper-1.0.2}/PKG-INFO +22 -2
- {universal_mapper-1.0.1 → universal_mapper-1.0.2}/README.md +21 -1
- {universal_mapper-1.0.1 → universal_mapper-1.0.2}/pyproject.toml +1 -1
- {universal_mapper-1.0.1 → universal_mapper-1.0.2}/pyproject.toml.orig +1 -1
- {universal_mapper-1.0.1 → universal_mapper-1.0.2}/src/universal_mapper/object_mapper.py +27 -6
- universal_mapper-1.0.2/src/universal_mapper/py.typed +0 -0
- {universal_mapper-1.0.1 → universal_mapper-1.0.2}/LICENSE +0 -0
- {universal_mapper-1.0.1 → universal_mapper-1.0.2}/src/universal_mapper/__init__.py +0 -0
- {universal_mapper-1.0.1 → universal_mapper-1.0.2}/src/universal_mapper/accessors/__init__.py +0 -0
- {universal_mapper-1.0.1 → universal_mapper-1.0.2}/src/universal_mapper/accessors/abstract_base.py +0 -0
- {universal_mapper-1.0.1 → universal_mapper-1.0.2}/src/universal_mapper/accessors/accessor_factory.py +0 -0
- {universal_mapper-1.0.1 → universal_mapper-1.0.2}/src/universal_mapper/accessors/collection.py +0 -0
- {universal_mapper-1.0.1 → universal_mapper-1.0.2}/src/universal_mapper/accessors/dict.py +0 -0
- {universal_mapper-1.0.1 → universal_mapper-1.0.2}/src/universal_mapper/accessors/object_accessors/__init__.py +0 -0
- {universal_mapper-1.0.1 → universal_mapper-1.0.2}/src/universal_mapper/accessors/object_accessors/default.py +0 -0
- {universal_mapper-1.0.1 → universal_mapper-1.0.2}/src/universal_mapper/accessors/object_accessors/object_accessor.py +0 -0
- {universal_mapper-1.0.1 → universal_mapper-1.0.2}/src/universal_mapper/accessors/object_accessors/pydantic.py +0 -0
- {universal_mapper-1.0.1 → universal_mapper-1.0.2}/src/universal_mapper/accessors/object_accessors/sqlalchemy.py +0 -0
- {universal_mapper-1.0.1 → universal_mapper-1.0.2}/src/universal_mapper/exceptions.py +0 -0
- {universal_mapper-1.0.1 → universal_mapper-1.0.2}/src/universal_mapper/type_utils.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: universal-mapper
|
|
3
|
-
Version: 1.0.
|
|
3
|
+
Version: 1.0.2
|
|
4
4
|
Summary: A Python library for mapping data between objects, models, and collections
|
|
5
5
|
License-Expression: MIT
|
|
6
6
|
License-File: LICENSE
|
|
@@ -23,10 +23,30 @@ The library requires Python 3.12 or later. It supports ordinary Python objects,
|
|
|
23
23
|
|
|
24
24
|
## License
|
|
25
25
|
|
|
26
|
-
Distributed under the [MIT License](LICENSE).
|
|
26
|
+
Distributed under the [MIT License](https://github.com/Krestomansy/universal-mapper/blob/main/LICENSE).
|
|
27
|
+
|
|
28
|
+
## Installation
|
|
29
|
+
|
|
30
|
+
Install the package with pip:
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
pip install universal-mapper
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
To install an optional integration, choose the corresponding extra:
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
pip install 'universal-mapper[pydantic]'
|
|
40
|
+
pip install 'universal-mapper[sqlalchemy]'
|
|
41
|
+
pip install 'universal-mapper[pydantic,sqlalchemy]'
|
|
42
|
+
```
|
|
27
43
|
|
|
28
44
|
## Versions
|
|
29
45
|
|
|
46
|
+
### 1.0.2 — 23.11.2026
|
|
47
|
+
|
|
48
|
+
- Improved type annotations for compatibility with type checkers.
|
|
49
|
+
|
|
30
50
|
### 1.0.1 — 23.11.2026
|
|
31
51
|
|
|
32
52
|
- Fixed documentation links and project metadata.
|
|
@@ -6,10 +6,30 @@ The library requires Python 3.12 or later. It supports ordinary Python objects,
|
|
|
6
6
|
|
|
7
7
|
## License
|
|
8
8
|
|
|
9
|
-
Distributed under the [MIT License](LICENSE).
|
|
9
|
+
Distributed under the [MIT License](https://github.com/Krestomansy/universal-mapper/blob/main/LICENSE).
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
Install the package with pip:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
pip install universal-mapper
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
To install an optional integration, choose the corresponding extra:
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
pip install 'universal-mapper[pydantic]'
|
|
23
|
+
pip install 'universal-mapper[sqlalchemy]'
|
|
24
|
+
pip install 'universal-mapper[pydantic,sqlalchemy]'
|
|
25
|
+
```
|
|
10
26
|
|
|
11
27
|
## Versions
|
|
12
28
|
|
|
29
|
+
### 1.0.2 — 23.11.2026
|
|
30
|
+
|
|
31
|
+
- Improved type annotations for compatibility with type checkers.
|
|
32
|
+
|
|
13
33
|
### 1.0.1 — 23.11.2026
|
|
14
34
|
|
|
15
35
|
- Fixed documentation links and project metadata.
|
|
@@ -26,7 +26,7 @@ type MappingType = Callable[[Any], Any] | dict[str | int, Callable[[Any], Any] |
|
|
|
26
26
|
T = TypeVar("T")
|
|
27
27
|
|
|
28
28
|
|
|
29
|
-
class
|
|
29
|
+
class _NullableMapperWrapper:
|
|
30
30
|
"""Handle the second part of the mapping process, `.to()`."""
|
|
31
31
|
|
|
32
32
|
def __init__(self, from_instance: Any, mapper: ObjectMapper) -> None:
|
|
@@ -34,14 +34,14 @@ class _MapperWrapper:
|
|
|
34
34
|
self._mapper = mapper
|
|
35
35
|
|
|
36
36
|
@overload
|
|
37
|
-
def to(self, to_class_or_instance: type[T]) -> T:
|
|
37
|
+
def to(self, to_class_or_instance: type[T]) -> T | None:
|
|
38
38
|
"""Map an object to the specified class."""
|
|
39
39
|
|
|
40
40
|
@overload
|
|
41
|
-
def to(self, to_class_or_instance: T) -> T:
|
|
41
|
+
def to(self, to_class_or_instance: T) -> T | None:
|
|
42
42
|
"""Update the fields of the specified object."""
|
|
43
43
|
|
|
44
|
-
def to(self, to_class_or_instance: type[T] | T) -> T:
|
|
44
|
+
def to(self, to_class_or_instance: type[T] | T) -> T | None:
|
|
45
45
|
"""Map to the specified class or update the fields of the specified object."""
|
|
46
46
|
_visited_ids_stack: set[int] = set()
|
|
47
47
|
return self._mapper._map_internal(
|
|
@@ -51,6 +51,17 @@ class _MapperWrapper:
|
|
|
51
51
|
)
|
|
52
52
|
|
|
53
53
|
|
|
54
|
+
class _MapperWrapper(_NullableMapperWrapper):
|
|
55
|
+
@overload
|
|
56
|
+
def to(self, to_class_or_instance: type[T]) -> T: ...
|
|
57
|
+
|
|
58
|
+
@overload
|
|
59
|
+
def to(self, to_class_or_instance: T) -> T: ...
|
|
60
|
+
|
|
61
|
+
def to(self, to_class_or_instance: type[T] | T) -> T:
|
|
62
|
+
return cast(T, super().to(to_class_or_instance))
|
|
63
|
+
|
|
64
|
+
|
|
54
65
|
class ObjectMapper:
|
|
55
66
|
"""
|
|
56
67
|
Map objects to a specified class, including Pydantic and SQLAlchemy models.
|
|
@@ -71,7 +82,9 @@ class ObjectMapper:
|
|
|
71
82
|
) -> MappingAccessor[T, Any, Any]:
|
|
72
83
|
return cls.__accessor_factory.get(target)
|
|
73
84
|
|
|
74
|
-
def add_mapping(
|
|
85
|
+
def add_mapping(
|
|
86
|
+
self, map_to: type[T], mapping: Callable[[Any], T] | dict[str | int, Callable[[Any], Any] | None]
|
|
87
|
+
) -> None:
|
|
75
88
|
"""Add or overwrite a mapping rule."""
|
|
76
89
|
self._mappings[map_to] = mapping
|
|
77
90
|
|
|
@@ -129,8 +142,16 @@ class ObjectMapper:
|
|
|
129
142
|
|
|
130
143
|
raise TypeMismatchError(source_type=source.type, target_type=target.type)
|
|
131
144
|
|
|
132
|
-
|
|
145
|
+
@overload
|
|
146
|
+
def map(self, from_instance: None) -> _NullableMapperWrapper: ...
|
|
147
|
+
|
|
148
|
+
@overload
|
|
149
|
+
def map(self, from_instance: T) -> _MapperWrapper: ...
|
|
150
|
+
|
|
151
|
+
def map(self, from_instance: object) -> _NullableMapperWrapper:
|
|
133
152
|
"""Start mapping from an object."""
|
|
153
|
+
if from_instance is None:
|
|
154
|
+
return _NullableMapperWrapper(from_instance, self)
|
|
134
155
|
return _MapperWrapper(from_instance, self)
|
|
135
156
|
|
|
136
157
|
def _map_internal(
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{universal_mapper-1.0.1 → universal_mapper-1.0.2}/src/universal_mapper/accessors/__init__.py
RENAMED
|
File without changes
|
{universal_mapper-1.0.1 → universal_mapper-1.0.2}/src/universal_mapper/accessors/abstract_base.py
RENAMED
|
File without changes
|
{universal_mapper-1.0.1 → universal_mapper-1.0.2}/src/universal_mapper/accessors/accessor_factory.py
RENAMED
|
File without changes
|
{universal_mapper-1.0.1 → universal_mapper-1.0.2}/src/universal_mapper/accessors/collection.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|