From 7777ac73753eb442c1655f197c0d93cb8066112e Mon Sep 17 00:00:00 2001 From: paul fisher Date: Fri, 6 Oct 2023 21:16:04 -0400 Subject: [PATCH] Add a note about why the fields of Slice are `@property`s. (#175) --- python-spec/src/somacore/types.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/python-spec/src/somacore/types.py b/python-spec/src/somacore/types.py index 3d5e8422..63606298 100644 --- a/python-spec/src/somacore/types.py +++ b/python-spec/src/somacore/types.py @@ -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]: ...