str-to-obj 2023.11__py3-none-any.whl → 2025.1__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,175 @@
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
8
+ import types as t
9
+ import typing as h
10
+
11
+ from logger_36 import LOGGER
12
+ from str_to_obj.type.annotation import annotation_t
13
+ from str_to_obj.type.hint import any_hint_h
14
+ from str_to_obj.type.type import type_t
15
+
16
+
17
+ @d.dataclass(slots=True, repr=False, eq=False)
18
+ class collection_t(annotation_t):
19
+ ACCEPTED_TYPES: h.ClassVar[tuple[type, ...]] = (list, set, tuple)
20
+
21
+ # Items of any type but None.
22
+ ANY_ITEMS_TYPES: h.ClassVar[h.Any | tuple[h.Any, ...]] = h.Any
23
+ ANY_LENGTH: h.ClassVar[tuple[int, ...]] = (0,)
24
+
25
+ items_types: any_hint_h | tuple[any_hint_h, ...] | type_t | tuple[type_t, ...] = (
26
+ ANY_ITEMS_TYPES
27
+ )
28
+ lengths: int | tuple[int, ...] = ANY_LENGTH
29
+
30
+ def __post_init__(self) -> None:
31
+ """"""
32
+ original_item_types = self.items_types
33
+ original_lengths = self.lengths
34
+
35
+ if isinstance(self.items_types, h.Sequence):
36
+ items_types = []
37
+ for stripe in self.items_types:
38
+ if isinstance(stripe, type_t):
39
+ items_types.append(stripe)
40
+ else:
41
+ items_types.append(type_t.NewForHint(stripe))
42
+ self.items_types = items_types
43
+ elif not isinstance(self.items_types, type_t):
44
+ self.items_types = type_t.NewForHint(self.items_types)
45
+
46
+ if isinstance(self.lengths, int):
47
+ self.lengths = (self.lengths,)
48
+ else:
49
+ self.lengths = tuple(sorted(self.lengths))
50
+
51
+ with LOGGER.AddedContextLevel("Collection Annotation"):
52
+ if isinstance(self.items_types, h.Sequence):
53
+ if max(self.lengths) > self.items_types.__len__():
54
+ LOGGER.StageIssue(
55
+ f'Allowed length(s) ("{original_lengths}") must not exceed '
56
+ f"the length of the item types sequence "
57
+ f'("{original_item_types}")'
58
+ )
59
+ if self.lengths != self.__class__.ANY_LENGTH:
60
+ for length in self.lengths:
61
+ if (not isinstance(length, int)) or (length < 0):
62
+ LOGGER.StageIssue(
63
+ f"Invalid length in {self.lengths}",
64
+ actual=length,
65
+ expected="strictly positive integer",
66
+ )
67
+
68
+ @classmethod
69
+ def NewForType(
70
+ cls,
71
+ stripe: any_hint_h | tuple[any_hint_h, ...] | type_t | tuple[type_t, ...],
72
+ /,
73
+ ) -> h.Self:
74
+ """"""
75
+ if not isinstance(stripe, (type_t | tuple[type_t, ...])):
76
+ stripe = type_t.NewForHint(stripe)
77
+
78
+ if stripe.type not in cls.ACCEPTED_TYPES:
79
+ with LOGGER.AddedContextLevel("Collection Annotation"):
80
+ LOGGER.StageIssue(
81
+ f"Invalid type",
82
+ actual=stripe.type.__name__,
83
+ expected=", ".join(_elm.__name__ for _elm in cls.ACCEPTED_TYPES),
84
+ )
85
+ return collection_t()
86
+
87
+ if stripe.elements is None:
88
+ return collection_t()
89
+
90
+ if (n_elements := stripe.elements.__len__()) == 1:
91
+ return collection_t(items_types=stripe.elements[0], lengths=1)
92
+
93
+ if (n_elements == 2) and (stripe.elements[1].type is t.EllipsisType):
94
+ return collection_t(items_types=stripe.elements[0], lengths=cls.ANY_LENGTH)
95
+
96
+ return collection_t(items_types=stripe.elements, lengths=n_elements)
97
+
98
+ def ValueIssues(self, value: list | set | tuple | h.Any, /) -> list[str]:
99
+ """"""
100
+ issues = annotation_t.ValueIssues(self, value)
101
+ if issues.__len__() > 0:
102
+ return issues
103
+
104
+ if (self.lengths != self.__class__.ANY_LENGTH) and (
105
+ value.__len__() not in self.lengths
106
+ ):
107
+ return [
108
+ f"{value}: Sequence of invalid length; "
109
+ f"Expected={' or '.join(map(str, self.lengths))}."
110
+ ]
111
+
112
+ if isinstance(self.items_types, h.Sequence):
113
+ if value.__len__() > self.items_types.__len__():
114
+ return [
115
+ f"{value}: Sequence too long. "
116
+ f"Expected=At most {self.items_types.__len__()} element(s)."
117
+ ]
118
+
119
+ output = []
120
+ for stripe, element in zip(self.items_types, value):
121
+ output.extend(stripe.ValueIssues(element))
122
+ return output
123
+
124
+ stripe: type_t = self.items_types
125
+ output = []
126
+ for element in value:
127
+ output.extend(stripe.ValueIssues(element))
128
+ return output
129
+
130
+
131
+ """
132
+ COPYRIGHT NOTICE
133
+
134
+ This software is governed by the CeCILL license under French law and
135
+ abiding by the rules of distribution of free software. You can use,
136
+ modify and/ or redistribute the software under the terms of the CeCILL
137
+ license as circulated by CEA, CNRS and INRIA at the following URL
138
+ "http://www.cecill.info".
139
+
140
+ As a counterpart to the access to the source code and rights to copy,
141
+ modify and redistribute granted by the license, users are provided only
142
+ with a limited warranty and the software's author, the holder of the
143
+ economic rights, and the successive licensors have only limited
144
+ liability.
145
+
146
+ In this respect, the user's attention is drawn to the risks associated
147
+ with loading, using, modifying and/or developing or reproducing the
148
+ software by the user in light of its specific status of free software,
149
+ that may mean that it is complicated to manipulate, and that also
150
+ therefore means that it is reserved for developers and experienced
151
+ professionals having in-depth computer knowledge. Users are therefore
152
+ encouraged to load and test the software's suitability as regards their
153
+ requirements in conditions enabling the security of their systems and/or
154
+ data to be ensured and, more generally, to use and operate it in the
155
+ same conditions as regards security.
156
+
157
+ The fact that you are presently reading this means that you have had
158
+ knowledge of the CeCILL license and that you accept its terms.
159
+
160
+ SEE LICENCE NOTICE: file README-LICENCE-utf8.txt at project source root.
161
+
162
+ This software is being developed by Eric Debreuve, a CNRS employee and
163
+ member of team Morpheme.
164
+ Team Morpheme is a joint team between Inria, CNRS, and UniCA.
165
+ It is hosted by the Centre Inria d'Université Côte d'Azur, Laboratory
166
+ I3S, and Laboratory iBV.
167
+
168
+ CNRS: https://www.cnrs.fr/index.php/en
169
+ Inria: https://www.inria.fr/en/
170
+ UniCA: https://univ-cotedazur.eu/
171
+ Centre Inria d'Université Côte d'Azur: https://www.inria.fr/en/centre/sophia/
172
+ I3S: https://www.i3s.unice.fr/en/
173
+ iBV: http://ibv.unice.fr/
174
+ Team Morpheme: https://team.inria.fr/morpheme/
175
+ """
@@ -0,0 +1,142 @@
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
8
+ import typing as h
9
+
10
+ from logger_36 import LOGGER
11
+ from str_to_obj.type.annotation import annotation_t
12
+
13
+ number_h = int | float
14
+
15
+
16
+ @d.dataclass(slots=True, repr=False, eq=False)
17
+ class number_t(annotation_t):
18
+ INFINITY_NEG: h.ClassVar[float] = -float("inf")
19
+ INFINITY_POS: h.ClassVar[float] = float("inf")
20
+ INFINITE_PRECISION: h.ClassVar[float] = 0.0
21
+
22
+ ACCEPTED_TYPES: h.ClassVar[tuple[type, ...]] = (int, float)
23
+ min: number_h = INFINITY_NEG
24
+ max: number_h = INFINITY_POS
25
+ min_inclusive: bool = True
26
+ max_inclusive: bool = True
27
+ precision: number_h = INFINITE_PRECISION
28
+
29
+ def __post_init__(self) -> None:
30
+ """"""
31
+ stripe = self.__class__
32
+
33
+ with LOGGER.AddedContextLevel("Number Annotation"):
34
+ if (self.min != stripe.INFINITY_NEG) and not isinstance(
35
+ self.min, number_h.__args__
36
+ ):
37
+ LOGGER.StageIssue(
38
+ f"Invalid type for min value {self.min}",
39
+ actual=type(self.min).__name__,
40
+ expected=number_h,
41
+ )
42
+ if (self.max != stripe.INFINITY_POS) and not isinstance(
43
+ self.max, number_h.__args__
44
+ ):
45
+ LOGGER.StageIssue(
46
+ f"Invalid type for max value {self.max}",
47
+ actual=type(self.max).__name__,
48
+ expected=number_h,
49
+ )
50
+ if (self.precision != stripe.INFINITE_PRECISION) and not isinstance(
51
+ self.precision, number_h.__args__
52
+ ):
53
+ LOGGER.StageIssue(
54
+ f"Invalid type for precision {self.precision}",
55
+ actual=type(self.precision).__name__,
56
+ expected=number_h,
57
+ )
58
+ if self.precision < 0:
59
+ LOGGER.StageIssue(f"Invalid, negative precision {self.precision}")
60
+ if (self.min > self.max) or (
61
+ (self.min == self.max)
62
+ and not (self.min_inclusive and self.max_inclusive)
63
+ ):
64
+ if self.min_inclusive:
65
+ opening = "["
66
+ else:
67
+ opening = "]"
68
+ if self.max_inclusive:
69
+ closing = "]"
70
+ else:
71
+ closing = "["
72
+ LOGGER.StageIssue(
73
+ f"Empty value interval {opening}{self.min},{self.max}{closing}"
74
+ )
75
+
76
+ def ValueIssues(self, value: number_h, /) -> list[str]:
77
+ """"""
78
+ issues = annotation_t.ValueIssues(self, value)
79
+ if issues.__len__() > 0:
80
+ return issues
81
+
82
+ if self.min <= value <= self.max:
83
+ if ((value == self.min) and not self.min_inclusive) or (
84
+ (value == self.max) and not self.max_inclusive
85
+ ):
86
+ return [f"{value}: Value outside prescribed interval."]
87
+
88
+ if (self.precision != self.__class__.INFINITE_PRECISION) and (
89
+ self.precision * int(value / self.precision) != value
90
+ ):
91
+ return [f"{value}: Value of higher precision than the prescribed one."]
92
+
93
+ return []
94
+ else:
95
+ return [f"{value}: Value outside prescribed interval."]
96
+
97
+
98
+ """
99
+ COPYRIGHT NOTICE
100
+
101
+ This software is governed by the CeCILL license under French law and
102
+ abiding by the rules of distribution of free software. You can use,
103
+ modify and/ or redistribute the software under the terms of the CeCILL
104
+ license as circulated by CEA, CNRS and INRIA at the following URL
105
+ "http://www.cecill.info".
106
+
107
+ As a counterpart to the access to the source code and rights to copy,
108
+ modify and redistribute granted by the license, users are provided only
109
+ with a limited warranty and the software's author, the holder of the
110
+ economic rights, and the successive licensors have only limited
111
+ liability.
112
+
113
+ In this respect, the user's attention is drawn to the risks associated
114
+ with loading, using, modifying and/or developing or reproducing the
115
+ software by the user in light of its specific status of free software,
116
+ that may mean that it is complicated to manipulate, and that also
117
+ therefore means that it is reserved for developers and experienced
118
+ professionals having in-depth computer knowledge. Users are therefore
119
+ encouraged to load and test the software's suitability as regards their
120
+ requirements in conditions enabling the security of their systems and/or
121
+ data to be ensured and, more generally, to use and operate it in the
122
+ same conditions as regards security.
123
+
124
+ The fact that you are presently reading this means that you have had
125
+ knowledge of the CeCILL license and that you accept its terms.
126
+
127
+ SEE LICENCE NOTICE: file README-LICENCE-utf8.txt at project source root.
128
+
129
+ This software is being developed by Eric Debreuve, a CNRS employee and
130
+ member of team Morpheme.
131
+ Team Morpheme is a joint team between Inria, CNRS, and UniCA.
132
+ It is hosted by the Centre Inria d'Université Côte d'Azur, Laboratory
133
+ I3S, and Laboratory iBV.
134
+
135
+ CNRS: https://www.cnrs.fr/index.php/en
136
+ Inria: https://www.inria.fr/en/
137
+ UniCA: https://univ-cotedazur.eu/
138
+ Centre Inria d'Université Côte d'Azur: https://www.inria.fr/en/centre/sophia/
139
+ I3S: https://www.i3s.unice.fr/en/
140
+ iBV: http://ibv.unice.fr/
141
+ Team Morpheme: https://team.inria.fr/morpheme/
142
+ """
@@ -0,0 +1,117 @@
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
8
+ import typing as h
9
+ from enum import Enum as enum_t
10
+ from pathlib import Path as pl_path_t
11
+
12
+ from str_to_obj.type.annotation import annotation_t
13
+ from str_to_obj.type.hint import annotated_hint_t
14
+
15
+
16
+ class path_type_e(enum_t):
17
+ document = 1
18
+ folder = 2
19
+ any = 3
20
+
21
+
22
+ class path_purpose_e(enum_t):
23
+ input = 1
24
+ output = 2
25
+ any = 3
26
+
27
+
28
+ @d.dataclass(slots=True, repr=False, eq=False)
29
+ class path_t(annotation_t):
30
+
31
+ ACCEPTED_TYPES: h.ClassVar[tuple[type, ...]] = (pl_path_t,)
32
+
33
+ type_: path_type_e
34
+ purpose: path_purpose_e
35
+
36
+ @classmethod
37
+ def NewAnnotatedType(
38
+ cls, type_: path_type_e, purpose: path_purpose_e, /
39
+ ) -> annotated_hint_t:
40
+ """"""
41
+ return h.Annotated[pl_path_t, cls(type_=type_, purpose=purpose)]
42
+
43
+ def ValueIssues(self, value: pl_path_t | h.Any, /) -> list[str]:
44
+ """
45
+ None: Unspecified path.
46
+ """
47
+ issues = annotation_t.ValueIssues(self, value)
48
+ if issues.__len__() > 0:
49
+ return issues
50
+
51
+ if self.purpose is not path_purpose_e.input:
52
+ return []
53
+
54
+ if value.exists():
55
+ if self.type_ is path_type_e.any:
56
+ if value.is_file() or value.is_dir():
57
+ return []
58
+ else:
59
+ return [f"{value}: Not a valid file or folder."]
60
+
61
+ if (self.type_ is path_type_e.document) and value.is_file():
62
+ return []
63
+
64
+ if (self.type_ is path_type_e.folder) and value.is_dir():
65
+ return []
66
+
67
+ return [
68
+ f"{value}: Non-existent file or folder, or file for folder, "
69
+ f"or folder for file."
70
+ ]
71
+
72
+
73
+ """
74
+ COPYRIGHT NOTICE
75
+
76
+ This software is governed by the CeCILL license under French law and
77
+ abiding by the rules of distribution of free software. You can use,
78
+ modify and/ or redistribute the software under the terms of the CeCILL
79
+ license as circulated by CEA, CNRS and INRIA at the following URL
80
+ "http://www.cecill.info".
81
+
82
+ As a counterpart to the access to the source code and rights to copy,
83
+ modify and redistribute granted by the license, users are provided only
84
+ with a limited warranty and the software's author, the holder of the
85
+ economic rights, and the successive licensors have only limited
86
+ liability.
87
+
88
+ In this respect, the user's attention is drawn to the risks associated
89
+ with loading, using, modifying and/or developing or reproducing the
90
+ software by the user in light of its specific status of free software,
91
+ that may mean that it is complicated to manipulate, and that also
92
+ therefore means that it is reserved for developers and experienced
93
+ professionals having in-depth computer knowledge. Users are therefore
94
+ encouraged to load and test the software's suitability as regards their
95
+ requirements in conditions enabling the security of their systems and/or
96
+ data to be ensured and, more generally, to use and operate it in the
97
+ same conditions as regards security.
98
+
99
+ The fact that you are presently reading this means that you have had
100
+ knowledge of the CeCILL license and that you accept its terms.
101
+
102
+ SEE LICENCE NOTICE: file README-LICENCE-utf8.txt at project source root.
103
+
104
+ This software is being developed by Eric Debreuve, a CNRS employee and
105
+ member of team Morpheme.
106
+ Team Morpheme is a joint team between Inria, CNRS, and UniCA.
107
+ It is hosted by the Centre Inria d'Université Côte d'Azur, Laboratory
108
+ I3S, and Laboratory iBV.
109
+
110
+ CNRS: https://www.cnrs.fr/index.php/en
111
+ Inria: https://www.inria.fr/en/
112
+ UniCA: https://univ-cotedazur.eu/
113
+ Centre Inria d'Université Côte d'Azur: https://www.inria.fr/en/centre/sophia/
114
+ I3S: https://www.i3s.unice.fr/en/
115
+ iBV: http://ibv.unice.fr/
116
+ Team Morpheme: https://team.inria.fr/morpheme/
117
+ """
@@ -1,38 +1,13 @@
1
- # Copyright CNRS/Inria/UNS
2
- # Contributor(s): Eric Debreuve (since 2023)
3
- #
4
- # eric.debreuve@cnrs.fr
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.
31
-
32
- from typing import Any, Sequence
33
-
34
-
35
- def TypeAsRichStr(value: Any, /, *, prefix: str = "") -> str:
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 typing as h
8
+
9
+
10
+ def TypeAsRichStr(value: h.Any, /, *, prefix: str = "") -> str:
36
11
  """
37
12
  Richer alternative (however, causes troubles with packages like TensorFlow):
38
13
  Additional parameter: relative_to_home: bool = True
@@ -46,10 +21,57 @@ def TypeAsRichStr(value: Any, /, *, prefix: str = "") -> str:
46
21
  return f"[yellow]{prefix}{type(value).__name__}[/]"
47
22
 
48
23
 
49
- def NameValueTypeAsRichStr(name: str, value: Any, /, *, separator: str = "=") -> str:
24
+ def NameValueTypeAsRichStr(name: str, value: h.Any, /, *, separator: str = "=") -> str:
50
25
  """"""
51
26
  formatted_type = TypeAsRichStr(value, prefix=":")
52
- if isinstance(value, Sequence) and (value.__len__() == 0):
27
+ if isinstance(value, h.Sequence) and (value.__len__() == 0):
53
28
  value = "[cyan]<empty>[/]"
54
29
 
55
30
  return f"[blue]{name}[/]{separator}{value}{formatted_type}"
31
+
32
+
33
+ """
34
+ COPYRIGHT NOTICE
35
+
36
+ This software is governed by the CeCILL license under French law and
37
+ abiding by the rules of distribution of free software. You can use,
38
+ modify and/ or redistribute the software under the terms of the CeCILL
39
+ license as circulated by CEA, CNRS and INRIA at the following URL
40
+ "http://www.cecill.info".
41
+
42
+ As a counterpart to the access to the source code and rights to copy,
43
+ modify and redistribute granted by the license, users are provided only
44
+ with a limited warranty and the software's author, the holder of the
45
+ economic rights, and the successive licensors have only limited
46
+ liability.
47
+
48
+ In this respect, the user's attention is drawn to the risks associated
49
+ with loading, using, modifying and/or developing or reproducing the
50
+ software by the user in light of its specific status of free software,
51
+ that may mean that it is complicated to manipulate, and that also
52
+ therefore means that it is reserved for developers and experienced
53
+ professionals having in-depth computer knowledge. Users are therefore
54
+ encouraged to load and test the software's suitability as regards their
55
+ requirements in conditions enabling the security of their systems and/or
56
+ data to be ensured and, more generally, to use and operate it in the
57
+ same conditions as regards security.
58
+
59
+ The fact that you are presently reading this means that you have had
60
+ knowledge of the CeCILL license and that you accept its terms.
61
+
62
+ SEE LICENCE NOTICE: file README-LICENCE-utf8.txt at project source root.
63
+
64
+ This software is being developed by Eric Debreuve, a CNRS employee and
65
+ member of team Morpheme.
66
+ Team Morpheme is a joint team between Inria, CNRS, and UniCA.
67
+ It is hosted by the Centre Inria d'Université Côte d'Azur, Laboratory
68
+ I3S, and Laboratory iBV.
69
+
70
+ CNRS: https://www.cnrs.fr/index.php/en
71
+ Inria: https://www.inria.fr/en/
72
+ UniCA: https://univ-cotedazur.eu/
73
+ Centre Inria d'Université Côte d'Azur: https://www.inria.fr/en/centre/sophia/
74
+ I3S: https://www.i3s.unice.fr/en/
75
+ iBV: http://ibv.unice.fr/
76
+ Team Morpheme: https://team.inria.fr/morpheme/
77
+ """
str_to_obj/main.py CHANGED
@@ -1,59 +1,35 @@
1
- # Copyright CNRS/Inria/UNS
2
- # Contributor(s): Eric Debreuve (since 2023)
3
- #
4
- # eric.debreuve@cnrs.fr
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
  import ast as bstr
33
- from types import NoneType
34
- from typing import Any
8
+ import types as t
9
+ import typing as h
35
10
 
36
11
  from str_to_obj.task.casting import CastValue
37
- from str_to_obj.type.hint_tree import any_hint_h, hint_tree_t
12
+ from str_to_obj.type.hint_tree import any_hint_h, hint_t
38
13
 
39
14
 
40
15
  def ObjectFromStr(
41
16
  string: str,
42
17
  /,
43
18
  *,
44
- expected_type: any_hint_h | hint_tree_t | type[NoneType] = None,
45
- ) -> tuple[Any, list[str]]:
19
+ expected_type: any_hint_h | hint_t | type[t.NoneType] = None,
20
+ ) -> tuple[h.Any, list[str]]:
46
21
  """
47
22
  expected_type: Must not be passed explicitly as None since None is interpreted as
48
23
  "no specific expected type". When expecting None, pass NoneType.
49
24
  """
50
- if expected_type is NoneType:
25
+ if expected_type is t.NoneType:
51
26
  if string.lower() == "none":
52
27
  issues = []
53
28
  else:
54
29
  issues = [f'{string}: Invalid value; Expected="NONE" or "None" or "none".']
55
30
  return None, issues
56
31
 
32
+ # value = _ObjectFromStr(string)
57
33
  try:
58
34
  value = bstr.literal_eval(string)
59
35
  except (SyntaxError, ValueError):
@@ -63,3 +39,67 @@ def ObjectFromStr(
63
39
  return value, []
64
40
 
65
41
  return CastValue(value, expected_type)
42
+
43
+
44
+ # def _ObjectFromStr(string: str | h.Any, /)-> h.Any:
45
+ # """"""
46
+ # # if not isinstance(string, str):
47
+ # # return string
48
+ #
49
+ # try:
50
+ # value = bstr.literal_eval(string)
51
+ # except (SyntaxError, ValueError):
52
+ # value = string
53
+ #
54
+ # # if isinstance(value, h.Sequence) and not isinstance(value, str):
55
+ # # stripe = type(value)
56
+ # # value = stripe(_ObjectFromStr(_elm) for _elm in value)
57
+ #
58
+ # return value
59
+
60
+
61
+ """
62
+ COPYRIGHT NOTICE
63
+
64
+ This software is governed by the CeCILL license under French law and
65
+ abiding by the rules of distribution of free software. You can use,
66
+ modify and/ or redistribute the software under the terms of the CeCILL
67
+ license as circulated by CEA, CNRS and INRIA at the following URL
68
+ "http://www.cecill.info".
69
+
70
+ As a counterpart to the access to the source code and rights to copy,
71
+ modify and redistribute granted by the license, users are provided only
72
+ with a limited warranty and the software's author, the holder of the
73
+ economic rights, and the successive licensors have only limited
74
+ liability.
75
+
76
+ In this respect, the user's attention is drawn to the risks associated
77
+ with loading, using, modifying and/or developing or reproducing the
78
+ software by the user in light of its specific status of free software,
79
+ that may mean that it is complicated to manipulate, and that also
80
+ therefore means that it is reserved for developers and experienced
81
+ professionals having in-depth computer knowledge. Users are therefore
82
+ encouraged to load and test the software's suitability as regards their
83
+ requirements in conditions enabling the security of their systems and/or
84
+ data to be ensured and, more generally, to use and operate it in the
85
+ same conditions as regards security.
86
+
87
+ The fact that you are presently reading this means that you have had
88
+ knowledge of the CeCILL license and that you accept its terms.
89
+
90
+ SEE LICENCE NOTICE: file README-LICENCE-utf8.txt at project source root.
91
+
92
+ This software is being developed by Eric Debreuve, a CNRS employee and
93
+ member of team Morpheme.
94
+ Team Morpheme is a joint team between Inria, CNRS, and UniCA.
95
+ It is hosted by the Centre Inria d'Université Côte d'Azur, Laboratory
96
+ I3S, and Laboratory iBV.
97
+
98
+ CNRS: https://www.cnrs.fr/index.php/en
99
+ Inria: https://www.inria.fr/en/
100
+ UniCA: https://univ-cotedazur.eu/
101
+ Centre Inria d'Université Côte d'Azur: https://www.inria.fr/en/centre/sophia/
102
+ I3S: https://www.i3s.unice.fr/en/
103
+ iBV: http://ibv.unice.fr/
104
+ Team Morpheme: https://team.inria.fr/morpheme/
105
+ """