Skip to content

Commit

Permalink
dev: Use types.EllipsisType instead of 'builtins.ellipsis' when we can
Browse files Browse the repository at this point in the history
The former is preferable as its not a private/internal type¹, but it's
only available on on Python ≥3.10.²

¹ <python/cpython#85976>
² <https://docs.python.org/3/library/types.html#types.EllipsisType>
  • Loading branch information
tsibley committed Aug 31, 2023
1 parent 2e67031 commit 5f3f65d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
5 changes: 2 additions & 3 deletions nextstrain/cli/runner/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import argparse
import builtins
from argparse import ArgumentParser
from typing import cast, List, Union, TYPE_CHECKING
# TODO: Use typing.TypeAlias once Python 3.10 is the minimum supported version.
Expand All @@ -14,7 +13,7 @@
from .. import config, env, hostenv
from ..argparse import DirectoryPath, SKIP_AUTO_DEFAULT_IN_HELP
from ..errors import UserError
from ..types import Env, Options, RunnerModule
from ..types import EllipsisType, Env, Options, RunnerModule
from ..util import prose_list, runner_name, runner_module, runner_help, warn
from ..volume import NamedVolume

Expand Down Expand Up @@ -72,7 +71,7 @@
% (configured_runner, runner_name(default_runner)))


RunnerExec: TypeAlias = List[Union[str, 'builtins.ellipsis']]
RunnerExec: TypeAlias = List[Union[str, EllipsisType]]


def register_runners(parser: ArgumentParser,
Expand Down
9 changes: 8 additions & 1 deletion nextstrain/cli/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import argparse
import builtins
import sys
import urllib.parse
from pathlib import Path
from typing import Any, Iterable, List, Mapping, Optional, Tuple, Union
Expand All @@ -12,6 +13,12 @@
from typing_extensions import Protocol, TypeAlias
from .volume import NamedVolume

# Re-export EllipsisType so we can paper over its absence from older Pythons
if sys.version_info >= (3, 10):
from types import EllipsisType
else:
EllipsisType: TypeAlias = 'builtins.ellipsis'

"""
An immutable mapping of (*name*, *value*) pairs representing a set of
additional environment variables to overlay on the current environment (e.g.
Expand All @@ -33,7 +40,7 @@

RunnerTestResults = List['RunnerTestResult']
RunnerTestResult = Tuple[str, 'RunnerTestResultStatus']
RunnerTestResultStatus: TypeAlias = Union[bool, None, 'builtins.ellipsis']
RunnerTestResultStatus: TypeAlias = Union[bool, None, EllipsisType]

RunnerUpdateStatus = Optional[bool]

Expand Down

0 comments on commit 5f3f65d

Please sign in to comment.