SynBioDex / pySBOL3

Native python implementation of SBOL 3.0 specification
MIT License
37 stars 16 forks source link

Clean up ReferencedObject typing #324

Open jakebeal opened 3 years ago

jakebeal commented 3 years ago

We are inconsistent about the type declarations regarding ReferencedObject properties. For example, Constraint uses type Union[Identified,str]: https://github.com/SynBioDex/pySBOL3/blob/57875793642ca25ad5d5307b85051d8be80e5801/sbol3/constraint.py#L19-L20

while Interface uses types List[str] rather than List[Union[Identified,str]] (or would it be better as Union[List[Identified],List[str])? https://github.com/SynBioDex/pySBOL3/blob/57875793642ca25ad5d5307b85051d8be80e5801/sbol3/interface.py#L13-L14

Since we do in fact allow union types, we should propagate that typing information appropriately.

tcmitchell commented 3 years ago

We could define an ObjectReference to be equivalent to Union[Identified, str] and then use that for the type declaration of variables throughout. Where a referenced object is desired we could then say foo: ObjectReference or bar: List[ObjectReference].

jakebeal commented 3 years ago

This would lose some of the typing information that we currently have, such as in the constructor for Location: https://github.com/SynBioDex/pySBOL3/blob/68726146b32eb3c12006549f21efdd7cd227da13/sbol3/location.py#L16

Is there a way to parameterize this to ObjectReference[Sequence], which would allow the best of both?