Closed kdmccormick closed 1 year ago
@regisb does this look good to you?
tests/helpers.py
has a function called run
. It takes in an optional parameter and optionally returns using t.Optional[T]
.
In Python<=3.10, there is no substitute for t.Optional[T]
.
In 3.10+ we can change it to T|None
, but we're not there yet
Context
Before Python 3.7, in order to fully annotate collections (lists, dicts, tuples), one had to import the type names from the
typing
module:Subscripting the built-in types directly (e.g.,
list[int]
) would result in a syntax error likeTypeError: 'type' object is not subscriptable
. This is unfortunate because Tutor thoroughly annotates all types, including nested data structures, which are harder to read when using the type names fromtyping
.After Python 3.7, though, the built-in collection types can be used directly:
Tutor supports all non-end-of-life (EOL) Python versions. Since Python 3.6 is EOL, we can start using Python 3.7 features. Of course, we will need to retain Python 3.7 compatibility until Jun 2023 and Python 3.8 compatibility until Oct 2024, so the
from __future__ import annotations
line will need to stick around until then.Acceptance Criteria
Throughout the entire Tutor codebase:
from __future__ import annotations
to the top of every module, right below the module's docstring.t.List
,t.Dict
,t.Set
,t.Tuple
, andt.Type
with their built-in equivalents:list
,dict
,set
,tuple
, andtype
.make test
still passes under Python 3.7, 3.8 and 3.9.