spdx-python-model 0.0.3__py3-none-any.whl → 0.0.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.
@@ -33,8 +33,10 @@ from typing import (
33
33
  Set,
34
34
  Tuple,
35
35
  Type,
36
+ TypeVar,
36
37
  Union,
37
38
  cast,
39
+ overload,
38
40
  )
39
41
 
40
42
 
@@ -540,10 +542,9 @@ class EnumProp(IRIProp):
540
542
  def validate(self, value) -> None:
541
543
  super().validate(value)
542
544
 
543
- valid_values = self.iri_values()
544
- if value not in valid_values:
545
+ if value not in self.iri_values():
545
546
  raise ValueError(
546
- f"'{value}' is not a valid value. Choose one of {' '.join(valid_values)}"
547
+ f"'{value}' is not a valid value. Choose one of {' '.join(self.iri_values())}"
547
548
  )
548
549
 
549
550
  def encode(self, encoder, value, state) -> None:
@@ -616,6 +617,7 @@ def register(
616
617
 
617
618
  register_lock = threading.Lock()
618
619
  NAMED_INDIVIDUALS: Set[str] = set()
620
+ T_SHACLObject = TypeVar("T_SHACLObject", bound="SHACLObject")
619
621
 
620
622
 
621
623
  @functools.total_ordering
@@ -861,7 +863,7 @@ class SHACLObject(object):
861
863
  ) as obj_s:
862
864
  self._encode_properties(obj_s, state)
863
865
 
864
- def _encode_properties(self, encoder, state):
866
+ def _encode_properties(self, encoder, state) -> None:
865
867
  for iri, prop, min_count, max_count, pyname, compact in self.__iter_props():
866
868
  value = self.__dict__["_obj_data"][iri]
867
869
  if prop.elide(value):
@@ -921,7 +923,9 @@ class SHACLObject(object):
921
923
 
922
924
  return obj
923
925
 
924
- def _decode_properties(self, decoder, objectset: Optional[SHACLObjectSet] = None):
926
+ def _decode_properties(
927
+ self, decoder, objectset: Optional[SHACLObjectSet] = None
928
+ ) -> None:
925
929
  for key in decoder.object_keys():
926
930
  if not self._decode_prop(decoder, key, objectset=objectset):
927
931
  raise KeyError(f"Unknown property '{key}'")
@@ -1019,7 +1023,9 @@ class SHACLExtensibleObject(SHACLObject):
1019
1023
  obj = cls(typ)
1020
1024
  return obj
1021
1025
 
1022
- def _decode_properties(self, decoder, objectset: Optional[SHACLObjectSet] = None):
1026
+ def _decode_properties(
1027
+ self, decoder, objectset: Optional[SHACLObjectSet] = None
1028
+ ) -> None:
1023
1029
  def decode_value(d):
1024
1030
  if not d.is_list():
1025
1031
  return d.read_value()
@@ -1042,7 +1048,7 @@ class SHACLExtensibleObject(SHACLObject):
1042
1048
  with decoder.read_property(key) as prop_d:
1043
1049
  self.__dict__["_obj_data"][key] = decode_value(prop_d)
1044
1050
 
1045
- def _encode_properties(self, encoder, state):
1051
+ def _encode_properties(self, encoder, state) -> None:
1046
1052
  super()._encode_properties(encoder, state)
1047
1053
  if self.CLOSED:
1048
1054
  return
@@ -1274,8 +1280,17 @@ class SHACLObjectSet(object):
1274
1280
  for child in o.iter_objects(recursive=True, visited=visited):
1275
1281
  yield child
1276
1282
 
1283
+ @overload
1284
+ def foreach_type(
1285
+ self, typ: str, *, match_subclass: bool = True
1286
+ ) -> Iterator[SHACLObject]: ...
1287
+ @overload
1288
+ def foreach_type(
1289
+ self, typ: Type[T_SHACLObject], *, match_subclass: bool = True
1290
+ ) -> Iterator[T_SHACLObject]: ...
1291
+
1277
1292
  def foreach_type(
1278
- self, typ: Union[str, SHACLObject], *, match_subclass: bool = True
1293
+ self, typ: Union[str, Type[T_SHACLObject]], *, match_subclass: bool = True
1279
1294
  ) -> Iterable[SHACLObject]:
1280
1295
  """
1281
1296
  Iterate over each object of a specified type (or subclass there of)
@@ -1287,15 +1302,16 @@ class SHACLObjectSet(object):
1287
1302
  if not isinstance(typ, str):
1288
1303
  if not isinstance(typ, type) or not issubclass(typ, SHACLObject):
1289
1304
  raise TypeError(f"Type must be derived from SHACLObject, got {typ}")
1290
- typ = cast(SHACLObject, typ)
1291
- typ = typ._OBJ_TYPE
1305
+ # This intermediate step is necessary for pyrefly...
1306
+ typ_class: Type[SHACLObject] = typ
1307
+ typ = typ_class._OBJ_TYPE
1292
1308
 
1293
1309
  if typ not in self.obj_by_type:
1294
1310
  return
1295
1311
 
1296
1312
  for exact, o in self.obj_by_type[typ]:
1297
1313
  if match_subclass or exact:
1298
- yield o
1314
+ yield cast(T_SHACLObject, o)
1299
1315
 
1300
1316
  def merge(self, *objectsets) -> "SHACLObjectSet":
1301
1317
  """
@@ -2,4 +2,4 @@
2
2
  # SPDX-License-Identifier: Apache-2.0
3
3
  #
4
4
 
5
- VERSION = "0.0.3"
5
+ VERSION = "0.0.4"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: spdx_python_model
3
- Version: 0.0.3
3
+ Version: 0.0.4
4
4
  Summary: SPDX Model Python Bindings
5
5
  Project-URL: Homepage, https://github.com/spdx/spdx-python-model
6
6
  Project-URL: Repository, https://github.com/spdx/spdx-python-model.git
@@ -0,0 +1,8 @@
1
+ spdx_python_model/__init__.py,sha256=lJ32voKHbyrbv-PsgyFy1LdPhsKB4Y88gQelGaP_Two,96
2
+ spdx_python_model/version.py,sha256=7GJtd_cWYam-P9cSel1jXGQZa68Cwf9GXb3J-QsSLDg,61
3
+ spdx_python_model/bindings/__init__.py,sha256=WT32Wx6JDbx6c3bo2Rn46FOE2peu2le19hFhwWUwc_M,43
4
+ spdx_python_model/bindings/v3_0_1.py,sha256=coRUR7CwCcuIG79fgzptsnW_dNt2ZyMIkVK3sZKM5gU,292040
5
+ spdx_python_model-0.0.4.dist-info/METADATA,sha256=4QxGyWQRF5lpVo4EV4aw6UXa2ZSRrbYh7XhVpj8bIL4,3216
6
+ spdx_python_model-0.0.4.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
7
+ spdx_python_model-0.0.4.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
8
+ spdx_python_model-0.0.4.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: hatchling 1.27.0
2
+ Generator: hatchling 1.28.0
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
@@ -1,8 +0,0 @@
1
- spdx_python_model/__init__.py,sha256=lJ32voKHbyrbv-PsgyFy1LdPhsKB4Y88gQelGaP_Two,96
2
- spdx_python_model/version.py,sha256=aiT8VbVq3T03qYU4Y4udHJKGEm3R9FvFaX2_YCvZP8s,61
3
- spdx_python_model/bindings/__init__.py,sha256=WT32Wx6JDbx6c3bo2Rn46FOE2peu2le19hFhwWUwc_M,43
4
- spdx_python_model/bindings/v3_0_1.py,sha256=kgduwF6q4Zww0LTq6Tm0cm9fScoFrpS1hJjUcq4HRsE,291543
5
- spdx_python_model-0.0.3.dist-info/METADATA,sha256=6kuikQVmUfKcR3-iFS7OeYdtAu7a3r89oXPezLqkZY0,3216
6
- spdx_python_model-0.0.3.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
7
- spdx_python_model-0.0.3.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
8
- spdx_python_model-0.0.3.dist-info/RECORD,,