Skip to content

Commit

Permalink
Add a note about why the fields of Slice are @propertys. (#175)
Browse files Browse the repository at this point in the history
  • Loading branch information
thetorpedodog authored Oct 7, 2023
1 parent 24f0303 commit 7777ac7
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions python-spec/src/somacore/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,18 @@ class Slice(Protocol[_T_co]):
``start``/``stop``/``step`` and would match, but are *not* slices.
"""

# We use @property here to indicate that these fields are read-only;
# just saying::
#
# start: Optional[_T_co]
#
# would imply that doing::
#
# some_slice.start = a_new_value
#
# was valid, thus making mypy whine (correctly!) that _T_co should be
# invariant rather than covariant.

@property
def start(self) -> Optional[_T_co]:
...
Expand Down

0 comments on commit 7777ac7

Please sign in to comment.