MultiProxPy 0.2.0__tar.gz → 0.2.1__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: MultiProxPy
3
- Version: 0.2.0
3
+ Version: 0.2.1
4
4
  Summary: An easy way to combine multiple objects into one
5
5
  License-Expression: Apache-2.0
6
6
  License-File: LICENSE
@@ -36,7 +36,8 @@ The grouping is very abstract and should work with any type of object.
36
36
 
37
37
  The best part is that your IDE will treat the proxy-object like one of the contained objects.
38
38
  It will suggest methods/attributes bound to that class:\
39
- ![img.png](https://github.com/CheesecakeTV/MultiProxPy/blob/main/assets/images/SuggestionsOnProxyObject.png)
39
+ ![img.png](https://github.com/CheesecakeTV/MultiProxPy/blob/main/assets/images/SuggestionsOnProxyObject.png)\
40
+ (The image might not show on PyPi. Here is the link: https://github.com/CheesecakeTV/MultiProxPy/blob/main/assets/images/SuggestionsOnProxyObject.png)
40
41
 
41
42
  Other examples can be found in the github-repository: https://github.com/CheesecakeTV/MultiProxPy
42
43
 
@@ -21,7 +21,8 @@ The grouping is very abstract and should work with any type of object.
21
21
 
22
22
  The best part is that your IDE will treat the proxy-object like one of the contained objects.
23
23
  It will suggest methods/attributes bound to that class:\
24
- ![img.png](https://github.com/CheesecakeTV/MultiProxPy/blob/main/assets/images/SuggestionsOnProxyObject.png)
24
+ ![img.png](https://github.com/CheesecakeTV/MultiProxPy/blob/main/assets/images/SuggestionsOnProxyObject.png)\
25
+ (The image might not show on PyPi. Here is the link: https://github.com/CheesecakeTV/MultiProxPy/blob/main/assets/images/SuggestionsOnProxyObject.png)
25
26
 
26
27
  Other examples can be found in the github-repository: https://github.com/CheesecakeTV/MultiProxPy
27
28
 
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "MultiProxPy"
3
- version = "0.2.0"
3
+ version = "0.2.1"
4
4
  packages = [
5
5
  { include = "MultiProxPy", from = "src" }
6
6
  ]
@@ -1,4 +1,4 @@
1
- from typing import Any, Callable, Iterable
1
+ from typing import Any, Callable, Iterable, TypeVar
2
2
  from MultiProxPy import MultiProxy
3
3
  from functools import wraps
4
4
 
@@ -11,7 +11,7 @@ def _typecheck_multiprox(fct: Callable):
11
11
  @wraps(fct)
12
12
  def inner(*args, **kwargs):
13
13
  if not isinstance(args[0], MultiProxy):
14
- raise TypeError("The passed object was not a MultiProxy.")
14
+ raise TypeError("The passed object is not a MultiProxy.")
15
15
 
16
16
  return fct(*args, **kwargs)
17
17
 
@@ -39,7 +39,7 @@ def get_inner_type(multi_proxy: MultiProxy | Any) -> type:
39
39
  """
40
40
  return object.__getattribute__(multi_proxy, "_type")
41
41
 
42
- def _assert_type_match(multi_proxy: MultiProxy | Any, assert_match: bool = True, *objects: object) -> bool:
42
+ def _assert_type_match(multi_proxy: MultiProxy | Any, *objects: object, assert_match: bool = True) -> bool:
43
43
  """
44
44
  Check if all objects
45
45
  :param multi_proxy:
@@ -57,6 +57,44 @@ def _assert_type_match(multi_proxy: MultiProxy | Any, assert_match: bool = True,
57
57
 
58
58
  return is_matching
59
59
 
60
+ T = TypeVar("T")
61
+ @_typecheck_multiprox
62
+ def append_object(multi_proxy: MultiProxy | Any, to_append: T, assert_type: bool = True) -> T:
63
+ """
64
+ Add a single object to a multi-proxy.
65
+ The added object is returned, so you can call this function inline
66
+
67
+ :param multi_proxy:
68
+ :param to_append:
69
+ :param assert_type:
70
+ :return:
71
+ """
72
+ _assert_type_match(multi_proxy, to_append, assert_match=assert_type)
73
+
74
+ inner_list = get_object_list(multi_proxy)
75
+ inner_list.append(to_append)
76
+ return to_append
77
+
78
+ def extend_proxy(multi_proxy: MultiProxy | Any, iter_to_extend: Iterable[T], assert_type: bool = True) -> Iterable[T]:
79
+ """
80
+ Adds all elements from iter_to_extend to the passed multi_proxy.
81
+ The passed iterable is returned, so you can call this function inline.
82
+
83
+ Just remember that some iterables depleat. If the returned iterable is empty, convert it to a list first.
84
+
85
+ :param multi_proxy:
86
+ :param iter_to_extend:
87
+ :param assert_type:
88
+ :return:
89
+ """
90
+ iter_tuple = tuple(iter_to_extend)
91
+ _assert_type_match(multi_proxy, *iter_tuple, assert_match=assert_type)
92
+
93
+ inner_list = get_object_list(multi_proxy)
94
+ inner_list.extend(iter_tuple)
95
+
96
+ return iter_to_extend
97
+
60
98
  @_typecheck_multiprox
61
99
  def append_objects(multi_proxy: MultiProxy | Any, *objects: object, assert_type: bool = True):
62
100
  """
@@ -67,7 +105,7 @@ def append_objects(multi_proxy: MultiProxy | Any, *objects: object, assert_type:
67
105
  :param assert_type:
68
106
  :return:
69
107
  """
70
- _assert_type_match(multi_proxy, assert_match=assert_type)
108
+ _assert_type_match(multi_proxy, *objects, assert_match=assert_type)
71
109
 
72
110
  inner_list = get_object_list(multi_proxy)
73
111
  for obj in objects:
@@ -132,3 +170,6 @@ def remove_all(multi_proxy: MultiProxy | Any):
132
170
  """
133
171
  inner_list = get_object_list(multi_proxy)
134
172
  inner_list.clear()
173
+
174
+
175
+
@@ -14,9 +14,8 @@ class MultiProxy:
14
14
  Do not call directly!
15
15
  Use group_objects instead!
16
16
  """
17
- assert objects, "At least one object is required to create a MultiProxy!"
18
-
19
17
  if assume_type is None:
18
+ assert objects, "At least one object or a specific type is required to create a MultiProxy!"
20
19
  assume_type = type(objects[0])
21
20
 
22
21
  super().__setattr__("_type", assume_type)
@@ -117,7 +116,6 @@ def group_objects(
117
116
  :param check_type_mismatch: False to go the dangerous route of mixing together types
118
117
  :return:
119
118
  """
120
-
121
119
  if check_type_mismatch:
122
120
  main_type = type(primary)
123
121
  all_mismatching = tuple(filter(lambda a:not isinstance(a, main_type), others))
@@ -134,5 +132,18 @@ def group_objects(
134
132
 
135
133
  return my_caller
136
134
 
135
+ def create_empty_proxy(object_type: type[inner_type]) -> inner_type:
136
+ """
137
+ Create an empty "group" of objects with the passed type.
138
+ This way, you may add the objects of that group later on.
139
+
140
+ :param object_type:
141
+ :return:
142
+ """
143
+ my_caller = MultiProxy(
144
+ assume_type=object_type,
145
+ )
146
+
147
+ return my_caller
137
148
 
138
149
 
@@ -0,0 +1,15 @@
1
+
2
+ from .MultiProxyClass import MultiProxy, group_objects, create_empty_proxy
3
+ from .ModifyMultiProxy import (
4
+ get_inner_type,
5
+ get_object_list,
6
+ append_objects,
7
+ remove_object_by_value,
8
+ remove_index,
9
+ remove_object,
10
+ remove_all,
11
+ append_object,
12
+ extend_proxy,
13
+ )
14
+
15
+ create_proxy = group_objects # Just an alias that might be easier for some people
@@ -1,3 +0,0 @@
1
-
2
- from .MultiProxyClass import MultiProxy, group_objects
3
- from .ModifyMultiProxy import get_inner_type, get_object_list, append_objects, remove_object_by_value, remove_index, remove_object, remove_all
File without changes