extendable 1.2.1__tar.gz → 1.3.0__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.
- {extendable-1.2.1 → extendable-1.3.0}/PKG-INFO +3 -2
- {extendable-1.2.1 → extendable-1.3.0}/src/extendable/main.py +19 -5
- {extendable-1.2.1 → extendable-1.3.0}/src/extendable/registry.py +9 -3
- extendable-1.3.0/src/extendable/version.py +1 -0
- extendable-1.2.1/src/extendable/version.py +0 -1
- {extendable-1.2.1 → extendable-1.3.0}/LICENSE +0 -0
- {extendable-1.2.1 → extendable-1.3.0}/README.md +0 -0
- {extendable-1.2.1 → extendable-1.3.0}/pyproject.toml +0 -0
- {extendable-1.2.1 → extendable-1.3.0}/src/extendable/__init__.py +0 -0
- {extendable-1.2.1 → extendable-1.3.0}/src/extendable/context.py +0 -0
- {extendable-1.2.1 → extendable-1.3.0}/src/extendable/exceptions.py +0 -0
- {extendable-1.2.1 → extendable-1.3.0}/src/extendable/py.typed +0 -0
- {extendable-1.2.1 → extendable-1.3.0}/src/extendable/utils.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: extendable
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.3.0
|
|
4
4
|
Summary: A lib to define class extendable at runtime.
|
|
5
5
|
Author-email: Laurent Mignon <laurent.mignon@acsone.eu>
|
|
6
6
|
Requires-Python: >=3.6
|
|
@@ -8,6 +8,7 @@ Description-Content-Type: text/markdown
|
|
|
8
8
|
Classifier: License :: OSI Approved :: MIT License
|
|
9
9
|
Classifier: Intended Audience :: Developers
|
|
10
10
|
Classifier: Operating System :: OS Independent
|
|
11
|
+
License-File: LICENSE
|
|
11
12
|
Requires-Dist: contextvars;python_version<'3.7'
|
|
12
13
|
Requires-Dist: types-contextvars;python_version<'3.7'
|
|
13
14
|
Requires-Dist: typing_extensions;python_version<'3.7'
|
|
@@ -24,6 +24,7 @@ if TYPE_CHECKING:
|
|
|
24
24
|
class ExtendableClassDef:
|
|
25
25
|
name: str
|
|
26
26
|
base_names: List[str]
|
|
27
|
+
original_base_names: List[str]
|
|
27
28
|
namespace: Dict[str, Any]
|
|
28
29
|
original_name: str
|
|
29
30
|
others_bases: List[Any]
|
|
@@ -44,7 +45,8 @@ class ExtendableClassDef:
|
|
|
44
45
|
self.name = namespace["__xreg_name__"]
|
|
45
46
|
self.original_name = original_name
|
|
46
47
|
self.others_bases = bases
|
|
47
|
-
self.base_names = namespace["__xreg_base_names__"] or []
|
|
48
|
+
self.base_names = namespace["__xreg_base_names__"].copy() or []
|
|
49
|
+
self.original_base_names = self.base_names.copy()
|
|
48
50
|
self.hierarchy = [self]
|
|
49
51
|
self.metaclass = metaclass
|
|
50
52
|
self.kwargs = kwargs
|
|
@@ -85,9 +87,9 @@ class ExtendableClassDef:
|
|
|
85
87
|
return clone
|
|
86
88
|
|
|
87
89
|
|
|
88
|
-
_extendable_class_defs_by_module: OrderedDict[
|
|
89
|
-
|
|
90
|
-
|
|
90
|
+
_extendable_class_defs_by_module: OrderedDict[str, List[ExtendableClassDef]] = (
|
|
91
|
+
collections.OrderedDict()
|
|
92
|
+
)
|
|
91
93
|
|
|
92
94
|
|
|
93
95
|
def __register_class_def__(module: str, cls_def: ExtendableClassDef) -> None:
|
|
@@ -106,7 +108,7 @@ class ExtendableMeta(ABCMeta):
|
|
|
106
108
|
|
|
107
109
|
@no_type_check
|
|
108
110
|
def __new__(metacls, name, bases, namespace, extends=None, **kwargs):
|
|
109
|
-
"""
|
|
111
|
+
"""Create the expected class and collect the class definition that will be used
|
|
110
112
|
at the end of registry load process to build the final class."""
|
|
111
113
|
class_def = None
|
|
112
114
|
if isinstance(extends, bool) and extends:
|
|
@@ -249,6 +251,18 @@ class ExtendableMeta(ABCMeta):
|
|
|
249
251
|
###############################################################
|
|
250
252
|
# concrete methods provided to the final class by the metaclass
|
|
251
253
|
###############################################################
|
|
254
|
+
def __instancecheck__(self, instance: Any) -> bool: # noqa: B902
|
|
255
|
+
"""Implement issubclass(sub, cls)."""
|
|
256
|
+
if not hasattr(instance, "__xreg_name__"):
|
|
257
|
+
return False
|
|
258
|
+
|
|
259
|
+
if instance.__xreg_name__ == self.__xreg_name__:
|
|
260
|
+
# this is the same class
|
|
261
|
+
return True
|
|
262
|
+
# self is a class and instance is an instance of a class
|
|
263
|
+
if self.__xreg_name__ in instance.__xreg_all_base_names__:
|
|
264
|
+
return True
|
|
265
|
+
return super().__instancecheck__(instance)
|
|
252
266
|
|
|
253
267
|
def __subclasscheck__(cls, subclass: Any) -> bool: # noqa: B902
|
|
254
268
|
"""Implement issubclass(sub, cls)."""
|
|
@@ -8,8 +8,9 @@ from .utils import LastOrderedSet
|
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
class ExtendableRegistryListener:
|
|
11
|
-
def on_registry_initialized(
|
|
12
|
-
|
|
11
|
+
def on_registry_initialized(
|
|
12
|
+
self, registry: "ExtendableClassesRegistry"
|
|
13
|
+
) -> None: ...
|
|
13
14
|
|
|
14
15
|
def before_init_registry(
|
|
15
16
|
self,
|
|
@@ -121,13 +122,18 @@ class ExtendableClassesRegistry:
|
|
|
121
122
|
# determine all the classes the component should inherit from
|
|
122
123
|
bases = LastOrderedSet[main.ExtendableMeta]()
|
|
123
124
|
for base_name in cls_def.base_names:
|
|
125
|
+
# the base_names contains all the bases for the final aggregated
|
|
126
|
+
# class. Here we check that all the base required to build the
|
|
127
|
+
# current hierarchy are already build.
|
|
124
128
|
if base_name not in self:
|
|
125
129
|
if idx != 0 or base_name != cls_def.name:
|
|
126
130
|
raise TypeError(
|
|
127
131
|
f"Pydnatic class '{name}' extends an non-existing "
|
|
128
132
|
f"extendable class '{base_name}'."
|
|
129
133
|
)
|
|
130
|
-
|
|
134
|
+
elif base_name in cls_def.original_base_names:
|
|
135
|
+
# The bases to inherit for the current class are the one
|
|
136
|
+
# defined into the original class definition.
|
|
131
137
|
parent_class = self[base_name]
|
|
132
138
|
bases.add(parent_class)
|
|
133
139
|
for other_base in class_def.others_bases:
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "1.3.0"
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = "1.2.1"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|