Skip to content

Commit c5f1e34

Browse files
author
notactuallyfinn
committed
renamed pythonized to native python
1 parent 246cf21 commit c5f1e34

11 files changed

Lines changed: 95 additions & 83 deletions

File tree

src/hermes/commands/deposit/invenio.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,7 @@ def _codemeta_to_invenio_deposition(self) -> dict:
616616
if len(keywords) == 0:
617617
keywords = None
618618
else:
619-
keywords = keywords.to_python()
619+
keywords = keywords.to_native_python()
620620

621621
# TODO: Use the fields currently set to `None`.
622622
# Some more fields are available but they most likely don't relate to software

src/hermes/model/api.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from typing_extensions import Self
1010

1111
from hermes.model.types import ld_dict
12-
from hermes.model.types.ld_container import PYTHONIZED_LD_CONTAINER
12+
from hermes.model.types.ld_container import NATIVE_LD_CONTAINER
1313
from hermes.model.types.ld_context import ALL_CONTEXTS
1414
from hermes.model.types.pyld_util import bundled_loader
1515

@@ -25,14 +25,14 @@ class SoftwareMetadata(ld_dict):
2525

2626
def __init__(
2727
self: Self,
28-
data: Union[dict[str, PYTHONIZED_LD_CONTAINER], None] = None,
28+
data: Union[dict[str, NATIVE_LD_CONTAINER], None] = None,
2929
extra_vocabs: Union[dict[str, str], None] = None
3030
) -> None:
3131
"""
3232
Create a new instance of an SoftwareMetadata.
3333
3434
Args:
35-
data (dict[str, PYTHONIZED_LD_CONTAINER] | None): The data the SoftwareMetadata object starts out with.
35+
data (dict[str, NATIVE_LD_CONTAINER] | None): The data the SoftwareMetadata object starts out with.
3636
extra_vocabs (dict[str, str] | None): Extra JSON_LD context for the object.
3737
3838
Returns:

src/hermes/model/merge/container.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,28 +24,28 @@
2424
class _ld_merge_container:
2525
"""
2626
Abstract base class for ld_merge_dict and ld_merge_list,
27-
providing the merge containers with an override of :meth:`ld_container._to_python`.
27+
providing the merge containers with an override of :meth:`ld_container._to_native_python`.
2828
See also :class:`ld_dict`, :class:`ld_list` and :class:`ld_container`.
2929
"""
3030

31-
def _to_python(
31+
def _to_native_python(
3232
self: Self,
3333
full_iri: str,
3434
ld_value: Union[EXPANDED_JSON_LD_VALUE, dict[str, EXPANDED_JSON_LD_VALUE], list[str], str]
3535
) -> Union["ld_merge_dict", "ld_merge_list", BASIC_TYPE, TIME_TYPE]:
3636
"""
37-
Returns a pythonized version of ``ld_value`` pretending the value is in ``self`` and ``full_iri`` its key.
37+
Returns a native python version of ``ld_value`` pretending the value is in ``self`` and ``full_iri`` its key.
3838
3939
Args:
4040
full_iri (str): The expanded iri of the key of ``ld_value`` / ``self`` (later if self is not a dictionary).
4141
ld_value (EXPANDED_JSON_LD_VALUE | dict[str, EXPANDED_JSON_LD_VALUE] | list[str] | str):
42-
The value thats pythonized value is requested. ``ld_value`` has to be valid expanded JSON-LD if it
42+
The value thats native python value is requested. ``ld_value`` has to be valid expanded JSON-LD if it
4343
was embeded in ``self._data``.
4444
4545
Returns:
46-
ld_merge_dict | ld_merge_list | BASIC_TYPE | TIME_TYPE: The pythonized value of ``ld_value``.
46+
ld_merge_dict | ld_merge_list | BASIC_TYPE | TIME_TYPE: The native python value of ``ld_value``.
4747
"""
48-
value = super()._to_python(full_iri, ld_value)
48+
value = super()._to_native_python(full_iri, ld_value)
4949
# replace ld_dicts with ld_merge_dicts
5050
if isinstance(value, ld_dict) and not isinstance(value, ld_merge_dict):
5151
value = ld_merge_dict(

src/hermes/model/types/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
(ld_list.is_ld_list, {"ld_container": ld_list}),
2020
(lambda c: isinstance(c, list), {"ld_container": ld_list}),
2121

22-
# pythonize items from lists (expanded set is already handled above)
22+
# convert items from lists (expanded set is already handled above) to native python
2323
(ld_container.is_typed_json_value, {"python": lambda c, **kw: ld_container.typed_ld_to_py([c], **kw)}),
2424
(ld_container.is_json_value, {"python": lambda c, **_: c["@value"]}),
2525
(ld_list.is_container, {"ld_container": lambda c, **kw: ld_list([c], **kw)}),
@@ -28,8 +28,8 @@
2828
]
2929
"""
3030
A list of tuples each containing a function to check if the conversion function (the second item in the tuple which
31-
converts the given object into a JSON_LD represented by an ld_container) is applicable for a given pythonized expanded
32-
JSON_LD value.
31+
converts the given object into a JSON_LD represented by an ld_container) is applicable for a given expanded JSON_LD
32+
value (given in native its native python version).
3333
"""
3434

3535

src/hermes/model/types/ld_container.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@
4040
dict[str, Union["JSON_LD_VALUE", BASIC_TYPE, TIME_TYPE, "ld_dict", "ld_list"]],
4141
]
4242
""" Type description of valid JSON_LD objects that are partially represented by ld_containers """
43-
PYTHONIZED_LD_CONTAINER: TypeAlias = Union[
44-
list[Union["PYTHONIZED_LD_CONTAINER", BASIC_TYPE, TIME_TYPE]],
45-
dict[str, Union["PYTHONIZED_LD_CONTAINER", BASIC_TYPE, TIME_TYPE]],
43+
NATIVE_LD_CONTAINER: TypeAlias = Union[
44+
list[Union["NATIVE_LD_CONTAINER", BASIC_TYPE, TIME_TYPE]],
45+
dict[str, Union["NATIVE_LD_CONTAINER", BASIC_TYPE, TIME_TYPE]],
4646
]
47-
""" Type description of the pythonized from of ld_containers (i.e. if the ld_container(s) is/ are replaced). """
47+
""" Type description of the native python version of ld_containers (i.e. if the ld_container(s) is/ are replaced). """
4848

4949

5050
class ld_container:
@@ -147,21 +147,22 @@ def ld_value(self: Self) -> EXPANDED_JSON_LD_VALUE:
147147
"""
148148
return self._data
149149

150-
def _to_python(
150+
def _to_native_python(
151151
self: Self,
152152
full_iri: str,
153153
ld_value: Union[EXPANDED_JSON_LD_VALUE, dict[str, EXPANDED_JSON_LD_VALUE], list[str], str]
154154
) -> Union["ld_container", BASIC_TYPE, TIME_TYPE]:
155155
"""
156-
Returns a pythonized version of the given value pretending the value is in self and full_iri its key.
156+
Returns a native python version of the given value pretending the value is in self and full_iri its key.
157157
158158
Args:
159159
full_iri (str): The expanded iri of the key of ld_value / self (later if self is not a dictionary).
160160
ld_value (EXPANDED_JSON_LD_VALUE | dict[str, EXPANDED_JSON_LD_VALUE] | list[str] | str): The value thats
161-
pythonized value is requested. ld_value has to be valid expanded JSON-LD if it were inside self._data.
161+
native python value is requested.
162+
ld_value has to be valid expanded JSON-LD if it were inside self._data.
162163
163164
Returns:
164-
ld_dict | ld_list | BASIC_TYPE | TIME_TYPE: The pythonized value of the ld_value.
165+
ld_dict | ld_list | BASIC_TYPE | TIME_TYPE: The native python value of the ld_value.
165166
"""
166167
if full_iri == "@id":
167168
# values of key "@id" only have to be compacted
@@ -300,7 +301,7 @@ def __str__(self: Self) -> str:
300301
Returns:
301302
(str): The representation of self.
302303
"""
303-
return str(self.to_python())
304+
return str(self.to_native_python())
304305

305306
def compact(
306307
self: Self, context: Optional[Union[list[Union[JSON_LD_CONTEXT_DICT, str]], JSON_LD_CONTEXT_DICT, str]] = None
@@ -319,7 +320,7 @@ def compact(
319320
self.ld_value, context or self.context, {"documentLoader": bundled_loader, "skipExpand": True}
320321
)
321322

322-
def to_python(self):
323+
def to_native_python(self):
323324
raise NotImplementedError()
324325

325326
@classmethod
@@ -451,14 +452,14 @@ def is_typed_json_value(cls: type[Self], ld_value: Any) -> bool:
451452
def typed_ld_to_py(cls: type[Self], data: list[dict[str, BASIC_TYPE]], **kwargs) -> Union[BASIC_TYPE, TIME_TYPE]:
452453
"""
453454
Returns the value of the given expanded JSON-LD value containing a value type converted into that type.
454-
Meaning the pythonized version of the JSON-LD value data is returned.
455+
Meaning the native python version of the JSON-LD value data is returned.
455456
ld_container.is_typed_ld_value(data) must return True.
456457
457458
Args:
458-
data (list[dict[str, BASIC_TYPE]]): The value that is that is converted into its pythonized from.
459+
data (list[dict[str, BASIC_TYPE]]): The value that is that is converted into its native python version.
459460
460461
Returns:
461-
BASIC_TYPE | TIME_TYPE: The pythonized version of data.
462+
BASIC_TYPE | TIME_TYPE: The native python version of data.
462463
"""
463464
# FIXME: #434 dates are not returned as datetime/ date/ time but as string
464465
ld_value = data[0]['@value']

src/hermes/model/types/ld_dict.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
ld_container,
1616
JSON_LD_CONTEXT_DICT,
1717
EXPANDED_JSON_LD_VALUE,
18-
PYTHONIZED_LD_CONTAINER,
18+
NATIVE_LD_CONTAINER,
1919
JSON_LD_VALUE,
2020
TIME_TYPE,
2121
BASIC_TYPE,
@@ -71,17 +71,17 @@ def __init__(
7171

7272
def __getitem__(self: Self, key: str) -> ld_list:
7373
"""
74-
Get the item with the given key in a pythonized form.\n
74+
Get the item with the given key in as a ld_list.\n
7575
If self contains no key, value pair with the given key, then an empty list is added as its value and returned.
7676
7777
Args:
7878
key (str): The key (compacted or expanded) to the item.
7979
8080
Returns:
81-
ld_list: The pythonized item at the key.
81+
ld_list: The ld_list item at the key.
8282
"""
8383
full_iri = self.ld_proc.expand_iri(self.active_ctx, key)
84-
return self._to_python(full_iri, self.data_dict[full_iri])
84+
return self._to_native_python(full_iri, self.data_dict[full_iri])
8585

8686
def __setitem__(self: Self, key: str, value: Union[JSON_LD_VALUE, BASIC_TYPE, TIME_TYPE, ld_dict, ld_list]) -> None:
8787
"""
@@ -262,14 +262,14 @@ def get(
262262
self: Self, key: str, default: Any = _NO_DEFAULT
263263
) -> Union[ld_list, Any]:
264264
"""
265-
Get the item with the given key in a pythonized form using the build in get.\n
265+
Get the item with the given key in as a ld_list using the build in get.\n
266266
If a KeyError is raised, return the default or reraise it if no default is given.
267267
268268
Args:
269269
key (str): The key (compacted or expanded) to the item.
270270
271271
Returns:
272-
ld_list: The pythonized item at the key.
272+
ld_list: The ld_list item at the key.
273273
274274
Raises:
275275
KeyError: If :meth:`__getitem__(key)` raised a KeyError and default isn't set.
@@ -342,26 +342,26 @@ def ref(self: Self) -> dict[Literal["@id"], str]:
342342
"""
343343
return {"@id": self.data_dict['@id']}
344344

345-
def to_python(self: Self) -> dict[str, Union[BASIC_TYPE, TIME_TYPE, PYTHONIZED_LD_CONTAINER]]:
345+
def to_native_python(self: Self) -> dict[str, Union[BASIC_TYPE, TIME_TYPE, NATIVE_LD_CONTAINER]]:
346346
"""
347-
Return a fully pythonized version of this object where all ld_container are replaced by lists and dicts.
347+
Return a native python version of this object where all ld_container are replaced by lists and dicts.
348348
349349
Returns:
350-
dict[str, BASIC_TYPE | TIME_TYPE | PYTHONIZED_LD_CONTAINER]: The fully pythonized version of self.
350+
dict[str, BASIC_TYPE | TIME_TYPE | NATIVE_LD_CONTAINER]: The native python version of self.
351351
"""
352352
res = {}
353353
for key in self.compact_keys():
354354
value = self[key]
355355
if isinstance(value, ld_container):
356-
value = value.to_python()
356+
value = value.to_native_python()
357357
res[key] = value
358358
return res
359359

360360
# FIXME: Allow from_dict to handle dicts containing ld_dicts and ld_lists
361361
@classmethod
362362
def from_dict(
363363
cls: type[Self],
364-
value: dict[str, PYTHONIZED_LD_CONTAINER],
364+
value: dict[str, NATIVE_LD_CONTAINER],
365365
*,
366366
parent: Optional[Union[ld_dict, ld_list]] = None,
367367
key: Optional[str] = None,
@@ -373,7 +373,7 @@ def from_dict(
373373
Uses the expansion of the JSON-LD Processor and not the one of ld_container.
374374
375375
Args:
376-
value (dict[str, PYTHONIZED_LD_CONTAINER]): The dict of values the ld_dict should be created from.
376+
value (dict[str, NATIVE_LD_CONTAINER]): The dict of values the ld_dict should be created from.
377377
parent (ld_dict | ld_list | None): The parent container of the new ld_list.
378378
key (str | None): The key into the inner most parent container representing a dict of the new ld_list.
379379
context (str | JSON_LD_CONTEXT_DICT | list[str | JSON_LD_CONTEXT_DICT] | None):

src/hermes/model/types/ld_list.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
ld_container,
1919
JSON_LD_CONTEXT_DICT,
2020
EXPANDED_JSON_LD_VALUE,
21-
PYTHONIZED_LD_CONTAINER,
21+
NATIVE_LD_CONTAINER,
2222
JSON_LD_VALUE,
2323
TIME_TYPE,
2424
BASIC_TYPE,
@@ -100,21 +100,21 @@ def __getitem__(
100100
self: Self, index: Union[int, slice]
101101
) -> Union[BASIC_TYPE, TIME_TYPE, ld_dict, ld_list, list[Union[BASIC_TYPE, TIME_TYPE, ld_dict, ld_list]]]:
102102
"""
103-
Get the item(s) at position index in a pythonized form.
103+
Get the item(s) at position index in their native python version.
104104
105105
Args:
106106
index (int | slice): The positon(s) from which the item(s) is/ are taken.
107107
108108
Returns:
109109
BASIC_TYPE | TIME_TYPE | ld_dict | ld_list | list[BASIC_TYPE | TIME_TYPE | ld_dict | ld_list]:
110-
The pythonized item(s) at index.
110+
The item(s) at index in the native python version.
111111
"""
112112
# handle slices by applying them to a list of indices and then getting the items at those
113113
if isinstance(index, slice):
114114
return [self[i] for i in [*range(len(self))][index]]
115115

116-
# get the item from the item_list and pythonize it. If necessary add the index.
117-
item = self._to_python(self.key, self.item_list[index])
116+
# get the item from the item_list and convert it into its native python version. If necessary add the index.
117+
item = self._to_native_python(self.key, self.item_list[index])
118118
if isinstance(item, ld_container):
119119
item.index = index
120120
return item
@@ -181,14 +181,14 @@ def __len__(self: Self) -> int:
181181

182182
def __iter__(self: Self) -> Generator[Union[BASIC_TYPE, TIME_TYPE, ld_dict, ld_list], None, None]:
183183
"""
184-
Returns an iterator over the pythonized values contained in self.
184+
Returns an iterator over the native python version of the values contained in self.
185185
186186
Returns:
187187
Generator[BASIC_TYPE | TIME_TYPE | ld_dict | ld_list, None, None]: The Iterator over self's values.
188188
"""
189-
# return an Iterator over each value in self in its pythonized from
189+
# return an Iterator over each value in self in its native python version
190190
for index, value in enumerate(self.item_list):
191-
item = self._to_python(self.key, value)
191+
item = self._to_native_python(self.key, value)
192192
# add which entry an ld_container is stored at, if item is an ld_container
193193
if isinstance(item, ld_container):
194194
item.index = index
@@ -536,15 +536,15 @@ def extend(self: Self, value: list[Union[JSON_LD_VALUE, BASIC_TYPE, TIME_TYPE, l
536536
for item in value:
537537
self.append(item)
538538

539-
def to_python(self: Self) -> list[Union[BASIC_TYPE, TIME_TYPE, PYTHONIZED_LD_CONTAINER]]:
539+
def to_native_python(self: Self) -> list[Union[BASIC_TYPE, TIME_TYPE, NATIVE_LD_CONTAINER]]:
540540
"""
541-
Return a fully pythonized version of this object where all ld_container are replaced by lists and dicts.
541+
Return a native python version of this object where all ld_container are replaced by lists and dicts.
542542
543543
Returns:
544-
list[BASIC_TYPE | TIME_TYPE | PYTHONIZED_LD_CONTAINER]: The fully pythonized version of self.
544+
list[BASIC_TYPE | TIME_TYPE | NATIVE_LD_CONTAINER]: The native python version of self.
545545
"""
546546
return [
547-
item.to_python() if isinstance(item, ld_container) else item
547+
item.to_native_python() if isinstance(item, ld_container) else item
548548
for item in self
549549
]
550550

0 commit comments

Comments
 (0)