Consider implement Protocol type for v3_x.SHACLObjectSet
Nobody has claimed this yet.
- Dominant language
- Jupyter Notebook
- Stars
- 5
- Forks
- 6
- PR merge metrics
- No merged PRs in 30d
Description
v3_0_1.SHACLObjectSet and v3_1.SHACLObjectSet are considered different types.
If user define a function def f() -> v3_0_1.SHACLObjectSet: ...,
the type of the object returned will not be considered the same as v3_1.SHACLObjectSet.
That defined function will be fixed to a particular version of model.
It is possible to solve this by define a "Protocol" structural type that contains similar members to v3_0_1.SHACLObjectSet and v3_1.SHACLObjectSet.
from typing import Protocol, Iterator, Optional
class SpdxObjectSet(Protocol):
def foreach(self) -> Iterator[object]: ...
def foreach_type(self, type_name: str, match_subclass: bool = True) -> Iterator[object]: ...
def find_by_id(self, spdx_id: str) -> Optional[object]: ...
def add(self, obj: object) -> None: ...
...
def f() -> SpdxObjectSet: ...
def g(spdx_object_set: SpdxObjectSet) -> None: ...
(this is a very mock example, will surely have flaws)
This SpdxObjectSet should work with SHACLObjectSet from bindings of any SPDX 3 version (as long as they got generated with the same set of members as SpdxObjectSet).
We should have SpdxObject for SHACLObject, and may be other types like one for ListProxy too. This will basically an abstract layer for developer ergonomic.
It should be very thin and very aware of resource consumption.
--
Note: I never implemented Protocol before and just learned about it. But looks like it can do the job.
In terms of architecture, there should be no change at the shacl2code side. shacl2code will keep generating each version of SPDX 3 model (at the generation time, shacl2code only know one version of model). Then it is the job of spdx-python-model to grouped them together as a version-agnostic type.
This should freed users of spdx-python-model from managing SPDX versions.
(The load() function already does a good job for helping determine a correct version of a model, but the returned model is still version-specific)
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading the generated v3_0_1.SHACLObjectSet and v3_1.SHACLObjectSet definitions, along with the load() function that selects a model version. Compare their shared members and review Python’s Protocol documentation. Done means version-agnostic types cover the proposed object-set and related model interfaces without changing shacl2code.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- developer-experience
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100