universal-mapper 1.0.0__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.
Files changed (20) hide show
  1. universal_mapper-1.0.0/README.md → universal_mapper-1.0.2/PKG-INFO +44 -3
  2. universal_mapper-1.0.0/PKG-INFO → universal_mapper-1.0.2/README.md +27 -16
  3. {universal_mapper-1.0.0 → universal_mapper-1.0.2}/pyproject.toml +7 -1
  4. {universal_mapper-1.0.0 → universal_mapper-1.0.2}/pyproject.toml.orig +7 -1
  5. {universal_mapper-1.0.0 → universal_mapper-1.0.2}/src/universal_mapper/object_mapper.py +27 -6
  6. universal_mapper-1.0.2/src/universal_mapper/py.typed +0 -0
  7. {universal_mapper-1.0.0 → universal_mapper-1.0.2}/LICENSE +0 -0
  8. {universal_mapper-1.0.0 → universal_mapper-1.0.2}/src/universal_mapper/__init__.py +0 -0
  9. {universal_mapper-1.0.0 → universal_mapper-1.0.2}/src/universal_mapper/accessors/__init__.py +0 -0
  10. {universal_mapper-1.0.0 → universal_mapper-1.0.2}/src/universal_mapper/accessors/abstract_base.py +0 -0
  11. {universal_mapper-1.0.0 → universal_mapper-1.0.2}/src/universal_mapper/accessors/accessor_factory.py +0 -0
  12. {universal_mapper-1.0.0 → universal_mapper-1.0.2}/src/universal_mapper/accessors/collection.py +0 -0
  13. {universal_mapper-1.0.0 → universal_mapper-1.0.2}/src/universal_mapper/accessors/dict.py +0 -0
  14. {universal_mapper-1.0.0 → universal_mapper-1.0.2}/src/universal_mapper/accessors/object_accessors/__init__.py +0 -0
  15. {universal_mapper-1.0.0 → universal_mapper-1.0.2}/src/universal_mapper/accessors/object_accessors/default.py +0 -0
  16. {universal_mapper-1.0.0 → universal_mapper-1.0.2}/src/universal_mapper/accessors/object_accessors/object_accessor.py +0 -0
  17. {universal_mapper-1.0.0 → universal_mapper-1.0.2}/src/universal_mapper/accessors/object_accessors/pydantic.py +0 -0
  18. {universal_mapper-1.0.0 → universal_mapper-1.0.2}/src/universal_mapper/accessors/object_accessors/sqlalchemy.py +0 -0
  19. {universal_mapper-1.0.0 → universal_mapper-1.0.2}/src/universal_mapper/exceptions.py +0 -0
  20. {universal_mapper-1.0.0 → universal_mapper-1.0.2}/src/universal_mapper/type_utils.py +0 -0
@@ -1,3 +1,20 @@
1
+ Metadata-Version: 2.4
2
+ Name: universal-mapper
3
+ Version: 1.0.2
4
+ Summary: A Python library for mapping data between objects, models, and collections
5
+ License-Expression: MIT
6
+ License-File: LICENSE
7
+ Requires-Dist: pydantic>=2 ; extra == 'pydantic'
8
+ Requires-Dist: sqlalchemy>=2 ; extra == 'sqlalchemy'
9
+ Requires-Python: >=3.12
10
+ Project-URL: Homepage, https://github.com/Krestomansy/universal-mapper
11
+ Project-URL: Repository, https://github.com/Krestomansy/universal-mapper
12
+ Project-URL: Documentation, https://github.com/Krestomansy/universal-mapper/blob/main/docs/README.md
13
+ Project-URL: Issues, https://github.com/Krestomansy/universal-mapper/issues
14
+ Provides-Extra: pydantic
15
+ Provides-Extra: sqlalchemy
16
+ Description-Content-Type: text/markdown
17
+
1
18
  # Universal Mapper
2
19
 
3
20
  Universal Mapper is a Python library for mapping data between objects, models, and collections. It supports nested structures, updates to existing objects, and custom mapping rules.
@@ -6,11 +23,35 @@ The library requires Python 3.12 or later. It supports ordinary Python objects,
6
23
 
7
24
  ## License
8
25
 
9
- 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
+ ```
10
43
 
11
44
  ## Versions
12
45
 
13
- ### 1.0.0 — Unreleased
46
+ ### 1.0.2 — 23.11.2026
47
+
48
+ - Improved type annotations for compatibility with type checkers.
49
+
50
+ ### 1.0.1 — 23.11.2026
51
+
52
+ - Fixed documentation links and project metadata.
53
+
54
+ ### 1.0.0 — 23.11.2026
14
55
 
15
56
  - Initial version with recursive mapping, object updates, and custom mapping rules.
16
57
  - Optional support for Pydantic and SQLAlchemy models.
@@ -127,7 +168,7 @@ result = mapper.map(Temperature(20.0)).to(TemperatureDto)
127
168
  assert result.fahrenheit == 68.0
128
169
  ```
129
170
 
130
- See the [documentation](docs/README.md) for more examples and details about integrations, collections, and error handling.
171
+ See the [documentation](https://github.com/Krestomansy/universal-mapper/blob/main/docs/README.md) for more examples and details about integrations, collections, and error handling.
131
172
 
132
173
  ## Inspiration
133
174
 
@@ -1,16 +1,3 @@
1
- Metadata-Version: 2.4
2
- Name: universal-mapper
3
- Version: 1.0.0
4
- Summary: A Python library for mapping data between objects, models, and collections
5
- License-Expression: MIT
6
- License-File: LICENSE
7
- Requires-Dist: pydantic>=2 ; extra == 'pydantic'
8
- Requires-Dist: sqlalchemy>=2 ; extra == 'sqlalchemy'
9
- Requires-Python: >=3.12
10
- Provides-Extra: pydantic
11
- Provides-Extra: sqlalchemy
12
- Description-Content-Type: text/markdown
13
-
14
1
  # Universal Mapper
15
2
 
16
3
  Universal Mapper is a Python library for mapping data between objects, models, and collections. It supports nested structures, updates to existing objects, and custom mapping rules.
@@ -19,11 +6,35 @@ The library requires Python 3.12 or later. It supports ordinary Python objects,
19
6
 
20
7
  ## License
21
8
 
22
- 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
+ ```
23
26
 
24
27
  ## Versions
25
28
 
26
- ### 1.0.0 — Unreleased
29
+ ### 1.0.2 — 23.11.2026
30
+
31
+ - Improved type annotations for compatibility with type checkers.
32
+
33
+ ### 1.0.1 — 23.11.2026
34
+
35
+ - Fixed documentation links and project metadata.
36
+
37
+ ### 1.0.0 — 23.11.2026
27
38
 
28
39
  - Initial version with recursive mapping, object updates, and custom mapping rules.
29
40
  - Optional support for Pydantic and SQLAlchemy models.
@@ -140,7 +151,7 @@ result = mapper.map(Temperature(20.0)).to(TemperatureDto)
140
151
  assert result.fahrenheit == 68.0
141
152
  ```
142
153
 
143
- See the [documentation](docs/README.md) for more examples and details about integrations, collections, and error handling.
154
+ See the [documentation](https://github.com/Krestomansy/universal-mapper/blob/main/docs/README.md) for more examples and details about integrations, collections, and error handling.
144
155
 
145
156
  ## Inspiration
146
157
 
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "universal-mapper"
3
- version = "1.0.0"
3
+ version = "1.0.2"
4
4
  description = "A Python library for mapping data between objects, models, and collections"
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.12"
@@ -8,6 +8,12 @@ license = "MIT"
8
8
  license-files = ["LICENSE"]
9
9
  dependencies = []
10
10
 
11
+ [project.urls]
12
+ Homepage = "https://github.com/Krestomansy/universal-mapper"
13
+ Repository = "https://github.com/Krestomansy/universal-mapper"
14
+ Documentation = "https://github.com/Krestomansy/universal-mapper/blob/main/docs/README.md"
15
+ Issues = "https://github.com/Krestomansy/universal-mapper/issues"
16
+
11
17
  [project.optional-dependencies]
12
18
  pydantic = ["pydantic>=2"]
13
19
  sqlalchemy = ["sqlalchemy>=2"]
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "universal-mapper"
3
- version = "1.0.0"
3
+ version = "1.0.2"
4
4
  description = "A Python library for mapping data between objects, models, and collections"
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.12"
@@ -8,6 +8,12 @@ license = "MIT"
8
8
  license-files = ["LICENSE"]
9
9
  dependencies = []
10
10
 
11
+ [project.urls]
12
+ Homepage = "https://github.com/Krestomansy/universal-mapper"
13
+ Repository = "https://github.com/Krestomansy/universal-mapper"
14
+ Documentation = "https://github.com/Krestomansy/universal-mapper/blob/main/docs/README.md"
15
+ Issues = "https://github.com/Krestomansy/universal-mapper/issues"
16
+
11
17
  [project.optional-dependencies]
12
18
  pydantic = [
13
19
  "pydantic>=2",
@@ -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 _MapperWrapper:
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(self, map_to: type[T], mapping: MappingType) -> None:
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
- def map(self, from_instance: Any) -> _MapperWrapper:
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