str-to-obj 2024.3__py3-none-any.whl → 2024.4__py3-none-any.whl
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.
- str_to_obj/__init__.py +52 -30
- str_to_obj/catalog/boolean.py +63 -37
- str_to_obj/catalog/callable.py +58 -34
- str_to_obj/catalog/choices.py +60 -37
- str_to_obj/catalog/collection.py +64 -41
- str_to_obj/catalog/number.py +63 -41
- str_to_obj/catalog/path.py +57 -34
- str_to_obj/interface/console.py +53 -30
- str_to_obj/main.py +52 -30
- str_to_obj/runtime/type.py +52 -30
- str_to_obj/runtime/value.py +52 -30
- str_to_obj/task/casting.py +52 -30
- str_to_obj/task/comparison.py +52 -30
- str_to_obj/task/inspection.py +53 -31
- str_to_obj/type/hint_tree.py +5 -3
- str_to_obj/version.py +54 -34
- {str_to_obj-2024.3.dist-info → str_to_obj-2024.4.dist-info}/METADATA +52 -31
- str_to_obj-2024.4.dist-info/RECORD +24 -0
- str_to_obj-2024.3.dist-info/RECORD +0 -24
- {str_to_obj-2024.3.dist-info → str_to_obj-2024.4.dist-info}/WHEEL +0 -0
- {str_to_obj-2024.3.dist-info → str_to_obj-2024.4.dist-info}/top_level.txt +0 -0
str_to_obj/__init__.py
CHANGED
@@ -1,33 +1,8 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
# This software is governed by the CeCILL license under French law and
|
7
|
-
# abiding by the rules of distribution of free software. You can use,
|
8
|
-
# modify and/ or redistribute the software under the terms of the CeCILL
|
9
|
-
# license as circulated by CEA, CNRS and INRIA at the following URL
|
10
|
-
# "http://www.cecill.info".
|
11
|
-
#
|
12
|
-
# As a counterpart to the access to the source code and rights to copy,
|
13
|
-
# modify and redistribute granted by the license, users are provided only
|
14
|
-
# with a limited warranty and the software's author, the holder of the
|
15
|
-
# economic rights, and the successive licensors have only limited
|
16
|
-
# liability.
|
17
|
-
#
|
18
|
-
# In this respect, the user's attention is drawn to the risks associated
|
19
|
-
# with loading, using, modifying and/or developing or reproducing the
|
20
|
-
# software by the user in light of its specific status of free software,
|
21
|
-
# that may mean that it is complicated to manipulate, and that also
|
22
|
-
# therefore means that it is reserved for developers and experienced
|
23
|
-
# professionals having in-depth computer knowledge. Users are therefore
|
24
|
-
# encouraged to load and test the software's suitability as regards their
|
25
|
-
# requirements in conditions enabling the security of their systems and/or
|
26
|
-
# data to be ensured and, more generally, to use and operate it in the
|
27
|
-
# same conditions as regards security.
|
28
|
-
#
|
29
|
-
# The fact that you are presently reading this means that you have had
|
30
|
-
# knowledge of the CeCILL license and that you accept its terms.
|
1
|
+
"""
|
2
|
+
Copyright CNRS/Inria/UniCA
|
3
|
+
Contributor(s): Eric Debreuve (eric.debreuve@cnrs.fr) since 2023
|
4
|
+
SEE COPYRIGHT NOTICE BELOW
|
5
|
+
"""
|
31
6
|
|
32
7
|
from str_to_obj.main import ObjectFromStr
|
33
8
|
from str_to_obj.runtime.value import INVALID_VALUE
|
@@ -35,3 +10,50 @@ from str_to_obj.task.casting import CastValue
|
|
35
10
|
from str_to_obj.type.annotation import annotation_t
|
36
11
|
from str_to_obj.type.type import type_t
|
37
12
|
from str_to_obj.version import __version__
|
13
|
+
|
14
|
+
|
15
|
+
"""
|
16
|
+
COPYRIGHT NOTICE
|
17
|
+
|
18
|
+
This software is governed by the CeCILL license under French law and
|
19
|
+
abiding by the rules of distribution of free software. You can use,
|
20
|
+
modify and/ or redistribute the software under the terms of the CeCILL
|
21
|
+
license as circulated by CEA, CNRS and INRIA at the following URL
|
22
|
+
"http://www.cecill.info".
|
23
|
+
|
24
|
+
As a counterpart to the access to the source code and rights to copy,
|
25
|
+
modify and redistribute granted by the license, users are provided only
|
26
|
+
with a limited warranty and the software's author, the holder of the
|
27
|
+
economic rights, and the successive licensors have only limited
|
28
|
+
liability.
|
29
|
+
|
30
|
+
In this respect, the user's attention is drawn to the risks associated
|
31
|
+
with loading, using, modifying and/or developing or reproducing the
|
32
|
+
software by the user in light of its specific status of free software,
|
33
|
+
that may mean that it is complicated to manipulate, and that also
|
34
|
+
therefore means that it is reserved for developers and experienced
|
35
|
+
professionals having in-depth computer knowledge. Users are therefore
|
36
|
+
encouraged to load and test the software's suitability as regards their
|
37
|
+
requirements in conditions enabling the security of their systems and/or
|
38
|
+
data to be ensured and, more generally, to use and operate it in the
|
39
|
+
same conditions as regards security.
|
40
|
+
|
41
|
+
The fact that you are presently reading this means that you have had
|
42
|
+
knowledge of the CeCILL license and that you accept its terms.
|
43
|
+
|
44
|
+
SEE LICENCE NOTICE: file README-LICENCE-utf8.txt at project source root.
|
45
|
+
|
46
|
+
This software is being developed by Eric Debreuve, a CNRS employee and
|
47
|
+
member of team Morpheme.
|
48
|
+
Team Morpheme is a joint team between Inria, CNRS, and UniCA.
|
49
|
+
It is hosted by the Centre Inria d'Université Côte d'Azur, Laboratory
|
50
|
+
I3S, and Laboratory iBV.
|
51
|
+
|
52
|
+
CNRS: https://www.cnrs.fr/index.php/en
|
53
|
+
Inria: https://www.inria.fr/en/
|
54
|
+
UniCA: https://univ-cotedazur.eu/
|
55
|
+
Centre Inria d'Université Côte d'Azur: https://www.inria.fr/en/centre/sophia/
|
56
|
+
I3S: https://www.i3s.unice.fr/en/
|
57
|
+
iBV: http://ibv.unice.fr/
|
58
|
+
Team Morpheme: https://team.inria.fr/morpheme/
|
59
|
+
"""
|
str_to_obj/catalog/boolean.py
CHANGED
@@ -1,44 +1,20 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
# modify and/ or redistribute the software under the terms of the CeCILL
|
9
|
-
# license as circulated by CEA, CNRS and INRIA at the following URL
|
10
|
-
# "http://www.cecill.info".
|
11
|
-
#
|
12
|
-
# As a counterpart to the access to the source code and rights to copy,
|
13
|
-
# modify and redistribute granted by the license, users are provided only
|
14
|
-
# with a limited warranty and the software's author, the holder of the
|
15
|
-
# economic rights, and the successive licensors have only limited
|
16
|
-
# liability.
|
17
|
-
#
|
18
|
-
# In this respect, the user's attention is drawn to the risks associated
|
19
|
-
# with loading, using, modifying and/or developing or reproducing the
|
20
|
-
# software by the user in light of its specific status of free software,
|
21
|
-
# that may mean that it is complicated to manipulate, and that also
|
22
|
-
# therefore means that it is reserved for developers and experienced
|
23
|
-
# professionals having in-depth computer knowledge. Users are therefore
|
24
|
-
# encouraged to load and test the software's suitability as regards their
|
25
|
-
# requirements in conditions enabling the security of their systems and/or
|
26
|
-
# data to be ensured and, more generally, to use and operate it in the
|
27
|
-
# same conditions as regards security.
|
28
|
-
#
|
29
|
-
# The fact that you are presently reading this means that you have had
|
30
|
-
# knowledge of the CeCILL license and that you accept its terms.
|
31
|
-
|
32
|
-
import dataclasses as dtcl
|
1
|
+
"""
|
2
|
+
Copyright CNRS/Inria/UniCA
|
3
|
+
Contributor(s): Eric Debreuve (eric.debreuve@cnrs.fr) since 2023
|
4
|
+
SEE COPYRIGHT NOTICE BELOW
|
5
|
+
"""
|
6
|
+
|
7
|
+
import dataclasses as d
|
33
8
|
import typing as h
|
34
9
|
from enum import Enum as enum_t
|
35
10
|
|
36
|
-
from
|
11
|
+
from logger_36 import FormattedMessage
|
12
|
+
from str_to_obj.type.annotation import annotation_t
|
37
13
|
from str_to_obj.type.hint import annotated_hint_t
|
38
14
|
|
39
15
|
|
40
16
|
class boolean_mode_e(enum_t):
|
41
|
-
#
|
17
|
+
# True value must be listed first.
|
42
18
|
true_false = ("True", "False")
|
43
19
|
yes_no = ("Yes", "No")
|
44
20
|
on_off = ("On", "Off")
|
@@ -47,7 +23,7 @@ class boolean_mode_e(enum_t):
|
|
47
23
|
_BOOLEAN_MODES = tuple(boolean_mode_e.__members__.keys())
|
48
24
|
|
49
25
|
|
50
|
-
@
|
26
|
+
@d.dataclass(slots=True, repr=False, eq=False)
|
51
27
|
class boolean_t(annotation_t):
|
52
28
|
|
53
29
|
ACCEPTED_TYPES: h.ClassVar[tuple[type, ...]] = (bool,)
|
@@ -65,9 +41,59 @@ class boolean_t(annotation_t):
|
|
65
41
|
if mode in _BOOLEAN_MODES:
|
66
42
|
mode = boolean_mode_e[mode].value
|
67
43
|
else:
|
68
|
-
valid = " or ".join(_BOOLEAN_MODES)
|
69
44
|
raise ValueError(
|
70
|
-
|
45
|
+
FormattedMessage(
|
46
|
+
"Invalid boolean mode",
|
47
|
+
actual=mode,
|
48
|
+
expected=" or ".join(_BOOLEAN_MODES),
|
49
|
+
)
|
71
50
|
)
|
72
51
|
|
73
52
|
return h.Annotated[bool, cls(mode=mode)]
|
53
|
+
|
54
|
+
|
55
|
+
"""
|
56
|
+
COPYRIGHT NOTICE
|
57
|
+
|
58
|
+
This software is governed by the CeCILL license under French law and
|
59
|
+
abiding by the rules of distribution of free software. You can use,
|
60
|
+
modify and/ or redistribute the software under the terms of the CeCILL
|
61
|
+
license as circulated by CEA, CNRS and INRIA at the following URL
|
62
|
+
"http://www.cecill.info".
|
63
|
+
|
64
|
+
As a counterpart to the access to the source code and rights to copy,
|
65
|
+
modify and redistribute granted by the license, users are provided only
|
66
|
+
with a limited warranty and the software's author, the holder of the
|
67
|
+
economic rights, and the successive licensors have only limited
|
68
|
+
liability.
|
69
|
+
|
70
|
+
In this respect, the user's attention is drawn to the risks associated
|
71
|
+
with loading, using, modifying and/or developing or reproducing the
|
72
|
+
software by the user in light of its specific status of free software,
|
73
|
+
that may mean that it is complicated to manipulate, and that also
|
74
|
+
therefore means that it is reserved for developers and experienced
|
75
|
+
professionals having in-depth computer knowledge. Users are therefore
|
76
|
+
encouraged to load and test the software's suitability as regards their
|
77
|
+
requirements in conditions enabling the security of their systems and/or
|
78
|
+
data to be ensured and, more generally, to use and operate it in the
|
79
|
+
same conditions as regards security.
|
80
|
+
|
81
|
+
The fact that you are presently reading this means that you have had
|
82
|
+
knowledge of the CeCILL license and that you accept its terms.
|
83
|
+
|
84
|
+
SEE LICENCE NOTICE: file README-LICENCE-utf8.txt at project source root.
|
85
|
+
|
86
|
+
This software is being developed by Eric Debreuve, a CNRS employee and
|
87
|
+
member of team Morpheme.
|
88
|
+
Team Morpheme is a joint team between Inria, CNRS, and UniCA.
|
89
|
+
It is hosted by the Centre Inria d'Université Côte d'Azur, Laboratory
|
90
|
+
I3S, and Laboratory iBV.
|
91
|
+
|
92
|
+
CNRS: https://www.cnrs.fr/index.php/en
|
93
|
+
Inria: https://www.inria.fr/en/
|
94
|
+
UniCA: https://univ-cotedazur.eu/
|
95
|
+
Centre Inria d'Université Côte d'Azur: https://www.inria.fr/en/centre/sophia/
|
96
|
+
I3S: https://www.i3s.unice.fr/en/
|
97
|
+
iBV: http://ibv.unice.fr/
|
98
|
+
Team Morpheme: https://team.inria.fr/morpheme/
|
99
|
+
"""
|
str_to_obj/catalog/callable.py
CHANGED
@@ -1,47 +1,24 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
# modify and/ or redistribute the software under the terms of the CeCILL
|
9
|
-
# license as circulated by CEA, CNRS and INRIA at the following URL
|
10
|
-
# "http://www.cecill.info".
|
11
|
-
#
|
12
|
-
# As a counterpart to the access to the source code and rights to copy,
|
13
|
-
# modify and redistribute granted by the license, users are provided only
|
14
|
-
# with a limited warranty and the software's author, the holder of the
|
15
|
-
# economic rights, and the successive licensors have only limited
|
16
|
-
# liability.
|
17
|
-
#
|
18
|
-
# In this respect, the user's attention is drawn to the risks associated
|
19
|
-
# with loading, using, modifying and/or developing or reproducing the
|
20
|
-
# software by the user in light of its specific status of free software,
|
21
|
-
# that may mean that it is complicated to manipulate, and that also
|
22
|
-
# therefore means that it is reserved for developers and experienced
|
23
|
-
# professionals having in-depth computer knowledge. Users are therefore
|
24
|
-
# encouraged to load and test the software's suitability as regards their
|
25
|
-
# requirements in conditions enabling the security of their systems and/or
|
26
|
-
# data to be ensured and, more generally, to use and operate it in the
|
27
|
-
# same conditions as regards security.
|
28
|
-
#
|
29
|
-
# The fact that you are presently reading this means that you have had
|
30
|
-
# knowledge of the CeCILL license and that you accept its terms.
|
31
|
-
|
32
|
-
import dataclasses as dtcl
|
1
|
+
"""
|
2
|
+
Copyright CNRS/Inria/UniCA
|
3
|
+
Contributor(s): Eric Debreuve (eric.debreuve@cnrs.fr) since 2023
|
4
|
+
SEE COPYRIGHT NOTICE BELOW
|
5
|
+
"""
|
6
|
+
|
7
|
+
import dataclasses as d
|
33
8
|
import typing as h
|
34
9
|
|
35
|
-
from str_to_obj import annotation_t
|
36
10
|
from str_to_obj.catalog.choices import choices_t
|
11
|
+
from str_to_obj.type.annotation import annotation_t
|
37
12
|
from str_to_obj.type.hint import annotated_hint_t
|
38
13
|
|
39
14
|
|
40
|
-
@
|
15
|
+
@d.dataclass(slots=True, repr=False, eq=False)
|
41
16
|
class callable_t(annotation_t):
|
42
17
|
ACCEPTED_TYPES: h.ClassVar[tuple[type, ...]] = (str,)
|
18
|
+
|
43
19
|
DUMMY_ENTRY: h.ClassVar[str] = "Dummy entry"
|
44
20
|
SEPARATOR: h.ClassVar[str] = ":"
|
21
|
+
|
45
22
|
kind: h.Literal["class", "function"]
|
46
23
|
choices: choices_t | None = None
|
47
24
|
allow_external: bool = False
|
@@ -73,3 +50,50 @@ class callable_t(annotation_t):
|
|
73
50
|
)
|
74
51
|
|
75
52
|
return h.Annotated[str, annotation]
|
53
|
+
|
54
|
+
|
55
|
+
"""
|
56
|
+
COPYRIGHT NOTICE
|
57
|
+
|
58
|
+
This software is governed by the CeCILL license under French law and
|
59
|
+
abiding by the rules of distribution of free software. You can use,
|
60
|
+
modify and/ or redistribute the software under the terms of the CeCILL
|
61
|
+
license as circulated by CEA, CNRS and INRIA at the following URL
|
62
|
+
"http://www.cecill.info".
|
63
|
+
|
64
|
+
As a counterpart to the access to the source code and rights to copy,
|
65
|
+
modify and redistribute granted by the license, users are provided only
|
66
|
+
with a limited warranty and the software's author, the holder of the
|
67
|
+
economic rights, and the successive licensors have only limited
|
68
|
+
liability.
|
69
|
+
|
70
|
+
In this respect, the user's attention is drawn to the risks associated
|
71
|
+
with loading, using, modifying and/or developing or reproducing the
|
72
|
+
software by the user in light of its specific status of free software,
|
73
|
+
that may mean that it is complicated to manipulate, and that also
|
74
|
+
therefore means that it is reserved for developers and experienced
|
75
|
+
professionals having in-depth computer knowledge. Users are therefore
|
76
|
+
encouraged to load and test the software's suitability as regards their
|
77
|
+
requirements in conditions enabling the security of their systems and/or
|
78
|
+
data to be ensured and, more generally, to use and operate it in the
|
79
|
+
same conditions as regards security.
|
80
|
+
|
81
|
+
The fact that you are presently reading this means that you have had
|
82
|
+
knowledge of the CeCILL license and that you accept its terms.
|
83
|
+
|
84
|
+
SEE LICENCE NOTICE: file README-LICENCE-utf8.txt at project source root.
|
85
|
+
|
86
|
+
This software is being developed by Eric Debreuve, a CNRS employee and
|
87
|
+
member of team Morpheme.
|
88
|
+
Team Morpheme is a joint team between Inria, CNRS, and UniCA.
|
89
|
+
It is hosted by the Centre Inria d'Université Côte d'Azur, Laboratory
|
90
|
+
I3S, and Laboratory iBV.
|
91
|
+
|
92
|
+
CNRS: https://www.cnrs.fr/index.php/en
|
93
|
+
Inria: https://www.inria.fr/en/
|
94
|
+
UniCA: https://univ-cotedazur.eu/
|
95
|
+
Centre Inria d'Université Côte d'Azur: https://www.inria.fr/en/centre/sophia/
|
96
|
+
I3S: https://www.i3s.unice.fr/en/
|
97
|
+
iBV: http://ibv.unice.fr/
|
98
|
+
Team Morpheme: https://team.inria.fr/morpheme/
|
99
|
+
"""
|
str_to_obj/catalog/choices.py
CHANGED
@@ -1,53 +1,29 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
# modify and/ or redistribute the software under the terms of the CeCILL
|
9
|
-
# license as circulated by CEA, CNRS and INRIA at the following URL
|
10
|
-
# "http://www.cecill.info".
|
11
|
-
#
|
12
|
-
# As a counterpart to the access to the source code and rights to copy,
|
13
|
-
# modify and redistribute granted by the license, users are provided only
|
14
|
-
# with a limited warranty and the software's author, the holder of the
|
15
|
-
# economic rights, and the successive licensors have only limited
|
16
|
-
# liability.
|
17
|
-
#
|
18
|
-
# In this respect, the user's attention is drawn to the risks associated
|
19
|
-
# with loading, using, modifying and/or developing or reproducing the
|
20
|
-
# software by the user in light of its specific status of free software,
|
21
|
-
# that may mean that it is complicated to manipulate, and that also
|
22
|
-
# therefore means that it is reserved for developers and experienced
|
23
|
-
# professionals having in-depth computer knowledge. Users are therefore
|
24
|
-
# encouraged to load and test the software's suitability as regards their
|
25
|
-
# requirements in conditions enabling the security of their systems and/or
|
26
|
-
# data to be ensured and, more generally, to use and operate it in the
|
27
|
-
# same conditions as regards security.
|
28
|
-
#
|
29
|
-
# The fact that you are presently reading this means that you have had
|
30
|
-
# knowledge of the CeCILL license and that you accept its terms.
|
31
|
-
|
32
|
-
import dataclasses as dtcl
|
1
|
+
"""
|
2
|
+
Copyright CNRS/Inria/UniCA
|
3
|
+
Contributor(s): Eric Debreuve (eric.debreuve@cnrs.fr) since 2023
|
4
|
+
SEE COPYRIGHT NOTICE BELOW
|
5
|
+
"""
|
6
|
+
|
7
|
+
import dataclasses as d
|
33
8
|
import typing as h
|
34
9
|
|
35
|
-
from
|
36
|
-
from str_to_obj import annotation_t
|
10
|
+
from logger_36 import LOGGER
|
11
|
+
from str_to_obj.type.annotation import annotation_t
|
37
12
|
from str_to_obj.type.hint import annotated_hint_t
|
38
13
|
|
39
14
|
|
40
|
-
@
|
15
|
+
@d.dataclass(slots=True, repr=False, eq=False)
|
41
16
|
class choices_t(annotation_t):
|
42
17
|
ACCEPTED_TYPES: h.ClassVar[tuple[type, ...]] = (str,)
|
18
|
+
|
43
19
|
options: h.Sequence[str]
|
44
20
|
|
45
21
|
def __post_init__(self) -> None:
|
46
22
|
""""""
|
47
|
-
with
|
23
|
+
with LOGGER.AddedContextLevel("Choices Annotation"):
|
48
24
|
for option in self.options:
|
49
25
|
if not isinstance(option, str):
|
50
|
-
|
26
|
+
LOGGER.StageIssue(
|
51
27
|
f'Invalid type of option "{option}"',
|
52
28
|
actual=type(option).__name__,
|
53
29
|
expected="str",
|
@@ -74,3 +50,50 @@ class choices_t(annotation_t):
|
|
74
50
|
options = " or ".join(options)
|
75
51
|
|
76
52
|
return [f"Invalid choice: Actual={value}; Expected={options}."]
|
53
|
+
|
54
|
+
|
55
|
+
"""
|
56
|
+
COPYRIGHT NOTICE
|
57
|
+
|
58
|
+
This software is governed by the CeCILL license under French law and
|
59
|
+
abiding by the rules of distribution of free software. You can use,
|
60
|
+
modify and/ or redistribute the software under the terms of the CeCILL
|
61
|
+
license as circulated by CEA, CNRS and INRIA at the following URL
|
62
|
+
"http://www.cecill.info".
|
63
|
+
|
64
|
+
As a counterpart to the access to the source code and rights to copy,
|
65
|
+
modify and redistribute granted by the license, users are provided only
|
66
|
+
with a limited warranty and the software's author, the holder of the
|
67
|
+
economic rights, and the successive licensors have only limited
|
68
|
+
liability.
|
69
|
+
|
70
|
+
In this respect, the user's attention is drawn to the risks associated
|
71
|
+
with loading, using, modifying and/or developing or reproducing the
|
72
|
+
software by the user in light of its specific status of free software,
|
73
|
+
that may mean that it is complicated to manipulate, and that also
|
74
|
+
therefore means that it is reserved for developers and experienced
|
75
|
+
professionals having in-depth computer knowledge. Users are therefore
|
76
|
+
encouraged to load and test the software's suitability as regards their
|
77
|
+
requirements in conditions enabling the security of their systems and/or
|
78
|
+
data to be ensured and, more generally, to use and operate it in the
|
79
|
+
same conditions as regards security.
|
80
|
+
|
81
|
+
The fact that you are presently reading this means that you have had
|
82
|
+
knowledge of the CeCILL license and that you accept its terms.
|
83
|
+
|
84
|
+
SEE LICENCE NOTICE: file README-LICENCE-utf8.txt at project source root.
|
85
|
+
|
86
|
+
This software is being developed by Eric Debreuve, a CNRS employee and
|
87
|
+
member of team Morpheme.
|
88
|
+
Team Morpheme is a joint team between Inria, CNRS, and UniCA.
|
89
|
+
It is hosted by the Centre Inria d'Université Côte d'Azur, Laboratory
|
90
|
+
I3S, and Laboratory iBV.
|
91
|
+
|
92
|
+
CNRS: https://www.cnrs.fr/index.php/en
|
93
|
+
Inria: https://www.inria.fr/en/
|
94
|
+
UniCA: https://univ-cotedazur.eu/
|
95
|
+
Centre Inria d'Université Côte d'Azur: https://www.inria.fr/en/centre/sophia/
|
96
|
+
I3S: https://www.i3s.unice.fr/en/
|
97
|
+
iBV: http://ibv.unice.fr/
|
98
|
+
Team Morpheme: https://team.inria.fr/morpheme/
|
99
|
+
"""
|
str_to_obj/catalog/collection.py
CHANGED
@@ -1,53 +1,29 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
# This software is governed by the CeCILL license under French law and
|
7
|
-
# abiding by the rules of distribution of free software. You can use,
|
8
|
-
# modify and/ or redistribute the software under the terms of the CeCILL
|
9
|
-
# license as circulated by CEA, CNRS and INRIA at the following URL
|
10
|
-
# "http://www.cecill.info".
|
11
|
-
#
|
12
|
-
# As a counterpart to the access to the source code and rights to copy,
|
13
|
-
# modify and redistribute granted by the license, users are provided only
|
14
|
-
# with a limited warranty and the software's author, the holder of the
|
15
|
-
# economic rights, and the successive licensors have only limited
|
16
|
-
# liability.
|
17
|
-
#
|
18
|
-
# In this respect, the user's attention is drawn to the risks associated
|
19
|
-
# with loading, using, modifying and/or developing or reproducing the
|
20
|
-
# software by the user in light of its specific status of free software,
|
21
|
-
# that may mean that it is complicated to manipulate, and that also
|
22
|
-
# therefore means that it is reserved for developers and experienced
|
23
|
-
# professionals having in-depth computer knowledge. Users are therefore
|
24
|
-
# encouraged to load and test the software's suitability as regards their
|
25
|
-
# requirements in conditions enabling the security of their systems and/or
|
26
|
-
# data to be ensured and, more generally, to use and operate it in the
|
27
|
-
# same conditions as regards security.
|
28
|
-
#
|
29
|
-
# The fact that you are presently reading this means that you have had
|
30
|
-
# knowledge of the CeCILL license and that you accept its terms.
|
1
|
+
"""
|
2
|
+
Copyright CNRS/Inria/UniCA
|
3
|
+
Contributor(s): Eric Debreuve (eric.debreuve@cnrs.fr) since 2023
|
4
|
+
SEE COPYRIGHT NOTICE BELOW
|
5
|
+
"""
|
31
6
|
|
32
7
|
from __future__ import annotations
|
33
8
|
|
34
|
-
import dataclasses as
|
9
|
+
import dataclasses as d
|
35
10
|
import types as t
|
36
11
|
import typing as h
|
37
12
|
|
38
|
-
from
|
39
|
-
from str_to_obj import annotation_t
|
13
|
+
from logger_36 import LOGGER
|
14
|
+
from str_to_obj.type.annotation import annotation_t
|
40
15
|
from str_to_obj.type.hint import any_hint_h
|
41
16
|
from str_to_obj.type.type import type_t
|
42
17
|
|
43
18
|
|
44
|
-
@
|
19
|
+
@d.dataclass(slots=True, repr=False, eq=False)
|
45
20
|
class collection_t(annotation_t):
|
46
|
-
|
21
|
+
ACCEPTED_TYPES: h.ClassVar[tuple[type, ...]] = (list, set, tuple)
|
22
|
+
|
23
|
+
# Items of any type but None.
|
47
24
|
ANY_ITEMS_TYPES: h.ClassVar[h.Any | tuple[h.Any, ...]] = h.Any
|
48
25
|
ANY_LENGTH: h.ClassVar[tuple[int, ...]] = (0,)
|
49
26
|
|
50
|
-
ACCEPTED_TYPES: h.ClassVar[tuple[type, ...]] = (list, set, tuple)
|
51
27
|
items_types: any_hint_h | tuple[any_hint_h, ...] | type_t | tuple[type_t, ...] = (
|
52
28
|
ANY_ITEMS_TYPES
|
53
29
|
)
|
@@ -74,10 +50,10 @@ class collection_t(annotation_t):
|
|
74
50
|
else:
|
75
51
|
self.lengths = tuple(sorted(self.lengths))
|
76
52
|
|
77
|
-
with
|
53
|
+
with LOGGER.AddedContextLevel("Collection Annotation"):
|
78
54
|
if isinstance(self.items_types, h.Sequence):
|
79
55
|
if max(self.lengths) > self.items_types.__len__():
|
80
|
-
|
56
|
+
LOGGER.StageIssue(
|
81
57
|
f'Allowed length(s) ("{original_lengths}") must not exceed '
|
82
58
|
f"the length of the item types sequence "
|
83
59
|
f'("{original_item_types}")'
|
@@ -85,7 +61,7 @@ class collection_t(annotation_t):
|
|
85
61
|
if self.lengths != self.__class__.ANY_LENGTH:
|
86
62
|
for length in self.lengths:
|
87
63
|
if (not isinstance(length, int)) or (length < 0):
|
88
|
-
|
64
|
+
LOGGER.StageIssue(
|
89
65
|
f"Invalid length in {self.lengths}",
|
90
66
|
actual=length,
|
91
67
|
expected="strictly positive integer",
|
@@ -102,8 +78,8 @@ class collection_t(annotation_t):
|
|
102
78
|
stripe = type_t.NewForHint(stripe)
|
103
79
|
|
104
80
|
if stripe.type not in cls.ACCEPTED_TYPES:
|
105
|
-
with
|
106
|
-
|
81
|
+
with LOGGER.AddedContextLevel("Collection Annotation"):
|
82
|
+
LOGGER.StageIssue(
|
107
83
|
f"Invalid type",
|
108
84
|
actual=stripe.type.__name__,
|
109
85
|
expected=", ".join(_elm.__name__ for _elm in cls.ACCEPTED_TYPES),
|
@@ -152,3 +128,50 @@ class collection_t(annotation_t):
|
|
152
128
|
for element in value:
|
153
129
|
output.extend(stripe.ValueIssues(element))
|
154
130
|
return output
|
131
|
+
|
132
|
+
|
133
|
+
"""
|
134
|
+
COPYRIGHT NOTICE
|
135
|
+
|
136
|
+
This software is governed by the CeCILL license under French law and
|
137
|
+
abiding by the rules of distribution of free software. You can use,
|
138
|
+
modify and/ or redistribute the software under the terms of the CeCILL
|
139
|
+
license as circulated by CEA, CNRS and INRIA at the following URL
|
140
|
+
"http://www.cecill.info".
|
141
|
+
|
142
|
+
As a counterpart to the access to the source code and rights to copy,
|
143
|
+
modify and redistribute granted by the license, users are provided only
|
144
|
+
with a limited warranty and the software's author, the holder of the
|
145
|
+
economic rights, and the successive licensors have only limited
|
146
|
+
liability.
|
147
|
+
|
148
|
+
In this respect, the user's attention is drawn to the risks associated
|
149
|
+
with loading, using, modifying and/or developing or reproducing the
|
150
|
+
software by the user in light of its specific status of free software,
|
151
|
+
that may mean that it is complicated to manipulate, and that also
|
152
|
+
therefore means that it is reserved for developers and experienced
|
153
|
+
professionals having in-depth computer knowledge. Users are therefore
|
154
|
+
encouraged to load and test the software's suitability as regards their
|
155
|
+
requirements in conditions enabling the security of their systems and/or
|
156
|
+
data to be ensured and, more generally, to use and operate it in the
|
157
|
+
same conditions as regards security.
|
158
|
+
|
159
|
+
The fact that you are presently reading this means that you have had
|
160
|
+
knowledge of the CeCILL license and that you accept its terms.
|
161
|
+
|
162
|
+
SEE LICENCE NOTICE: file README-LICENCE-utf8.txt at project source root.
|
163
|
+
|
164
|
+
This software is being developed by Eric Debreuve, a CNRS employee and
|
165
|
+
member of team Morpheme.
|
166
|
+
Team Morpheme is a joint team between Inria, CNRS, and UniCA.
|
167
|
+
It is hosted by the Centre Inria d'Université Côte d'Azur, Laboratory
|
168
|
+
I3S, and Laboratory iBV.
|
169
|
+
|
170
|
+
CNRS: https://www.cnrs.fr/index.php/en
|
171
|
+
Inria: https://www.inria.fr/en/
|
172
|
+
UniCA: https://univ-cotedazur.eu/
|
173
|
+
Centre Inria d'Université Côte d'Azur: https://www.inria.fr/en/centre/sophia/
|
174
|
+
I3S: https://www.i3s.unice.fr/en/
|
175
|
+
iBV: http://ibv.unice.fr/
|
176
|
+
Team Morpheme: https://team.inria.fr/morpheme/
|
177
|
+
"""
|