Skip to content

Commit

Permalink
Merge pull request #1068 from sirosen/fixup-mypy-config
Browse files Browse the repository at this point in the history
Fix mypy configuration in tox and CI, control python versions and update click-type-test usages
  • Loading branch information
sirosen authored Jan 7, 2025
2 parents 805c68c + d005099 commit 39d7110
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 44 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ jobs:
cpythons:
- "3.13"
tox-environments:
- "mypy"
- "mypy-minpython"
- "mypy-maxpython"
- "reference"
- "twine-check"
cache-key-prefix: "quality"
Expand Down
10 changes: 9 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ test = [
"pytest>=7",
"pytest-xdist<4",
"pytest-timeout<3",
"click-type-test==1.0.0;python_version>='3.10'",
"click-type-test==1.1.0;python_version>='3.10'",
"responses==0.25.3",
# loading test fixture data
"ruamel.yaml==0.18.9",
Expand All @@ -60,6 +60,14 @@ test = [
[project.scripts]
globus = "globus_cli:main"

[dependency-groups]
typing = [
"mypy==1.14.1",
"types-jwt",
"types-requests",
"types-jmespath",
]

[tool.setuptools.dynamic.version]
attr = "globus_cli.version.__version__"

Expand Down
14 changes: 10 additions & 4 deletions src/globus_cli/commands/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,17 @@ def get_metavar(self, param: click.Parameter) -> str:
return "Key=Value"

def get_type_annotation(self, param: click.Parameter) -> type:
return tuple[str, str]
# this is a "<typing special form>" vs "type" issue, so type ignore for now
# click-type-test has an issue for improving this, with details, see:
# https://github.com/sirosen/click-type-test/issues/14
return t.Tuple[str, str] # type: ignore[return-value]

def convert(
self,
value: str | None,
param: click.Parameter | None,
ctx: click.Context | None,
) -> t.Tuple[str, str] | None:
) -> tuple[str, str] | None:
value = super().convert(value, param, ctx)
if value is None:
return None
Expand All @@ -45,14 +48,17 @@ def get_metavar(self, param: click.Parameter) -> str:
return "Key:Value"

def get_type_annotation(self, param: click.Parameter) -> type:
return tuple[str, str]
# this is a "<typing special form>" vs "type" issue, so type ignore for now
# click-type-test has an issue for improving this, with details, see:
# https://github.com/sirosen/click-type-test/issues/14
return t.Tuple[str, str] # type: ignore[return-value]

def convert(
self,
value: str | None,
param: click.Parameter | None,
ctx: click.Context | None,
) -> t.Tuple[str, str] | None:
) -> tuple[str, str] | None:
value = super().convert(value, param, ctx)
if value is None:
return None
Expand Down
9 changes: 1 addition & 8 deletions src/globus_cli/commands/gcp/set_subscription_id.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from __future__ import annotations

import typing as t
import uuid

import click
Expand All @@ -13,15 +12,9 @@


class GCPSubscriptionIdType(click.ParamType):
def get_type_annotation(self, _: click.Parameter) -> type:
return t.cast(type, uuid.UUID | ExplicitNullType)

def convert(
self, value: str, param: click.Parameter | None, ctx: click.Context | None
) -> t.Any:
if ctx and ctx.resilient_parsing:
return None

) -> uuid.UUID | ExplicitNullType:
if value.lower() == "null":
return EXPLICIT_NULL

Expand Down
14 changes: 7 additions & 7 deletions src/globus_cli/commands/gcs/endpoint/set_subscription_id.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import sys
import typing as t
import uuid

Expand All @@ -10,17 +11,16 @@
from globus_cli.parsing import command, endpoint_id_arg
from globus_cli.termio import display

if sys.version_info >= (3, 9):
from typing import Literal
else:
from typing_extensions import Literal

class GCSSubscriptionIdType(click.ParamType):
def get_type_annotation(self, _: click.Parameter) -> type:
return t.cast(type, uuid.UUID | t.Literal["DEFAULT"] | ExplicitNullType)

class GCSSubscriptionIdType(click.ParamType):
def convert(
self, value: str, param: click.Parameter | None, ctx: click.Context | None
) -> t.Any:
if ctx and ctx.resilient_parsing:
return None

) -> uuid.UUID | Literal["DEFAULT"] | ExplicitNullType:
if value.lower() == "null":
return EXPLICIT_NULL
elif value.lower() == "default":
Expand Down
5 changes: 1 addition & 4 deletions src/globus_cli/commands/gcs/endpoint/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,12 @@


class SubscriptionIdType(click.ParamType):
def get_type_annotation(self, _: click.Parameter) -> type:
return t.cast(type, str | ExplicitNullType)

def get_metavar(self, _: click.Parameter) -> t.Optional[str]:
return "[<uuid>|DEFAULT|null]"

def convert(
self, value: str, param: click.Parameter | None, ctx: click.Context | None
) -> t.Any:
) -> str | ExplicitNullType | None:
if value is None or (ctx and ctx.resilient_parsing):
return None
if value.lower() == "null":
Expand Down
5 changes: 1 addition & 4 deletions src/globus_cli/commands/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,12 @@
class GCSEndpointType(click.ParamType):
name = "GCS Server"

def get_type_annotation(self, _: click.Parameter) -> type:
return t.cast(type, t.Union[uuid.UUID, tuple[uuid.UUID, uuid.UUID]])

def get_metavar(self, _: t.Optional[click.Parameter]) -> str:
return "<endpoint_id>[:<collection_id>]"

def convert(
self, value: t.Any, param: Parameter | None, ctx: Context | None
) -> t.Any:
) -> uuid.UUID | tuple[uuid.UUID, uuid.UUID]:
if isinstance(value, uuid.UUID):
return value
elif isinstance(value, tuple) and len(value) == 2:
Expand Down
2 changes: 1 addition & 1 deletion src/globus_cli/parsing/param_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def type_annotation(self) -> type:
return bool

if isinstance(self.type, EndpointPlusPath):
return self.type.get_type_annotation(self) | None # type: ignore[return-value] # noqa: E501
return t.Union[self.type.get_type_annotation(self), None] # type: ignore[return-value] # noqa: E501

raise NotImplementedError(
"OneUseOption requires a type annotation in this case."
Expand Down
7 changes: 5 additions & 2 deletions src/globus_cli/parsing/param_types/endpoint_plus_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,13 @@ def __init__(self, *args: t.Any, **kwargs: t.Any) -> None:
super().__init__(*args, **kwargs)

def get_type_annotation(self, param: click.Parameter) -> type:
# this is a "<typing special form>" vs "type" issue, so type ignore for now
# click-type-test has an issue for improving this, with details, see:
# https://github.com/sirosen/click-type-test/issues/14
if self.path_required:
return tuple[uuid.UUID, str]
return t.Tuple[uuid.UUID, str] # type: ignore[return-value]
else:
return tuple[uuid.UUID, str | None]
return t.Tuple[uuid.UUID, t.Union[str, None]] # type: ignore[return-value]

def get_metavar(self, param: click.Parameter | None) -> str:
"""
Expand Down
22 changes: 10 additions & 12 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ envlist =
cov-combine
cov-report
mypy
minversion = 4.3.5
minversion = 4.22.0

[testenv]
package = wheel
Expand Down Expand Up @@ -43,8 +43,8 @@ commands =
localsdk: python -c 'import os, subprocess, sys; subprocess.run([sys.executable, "-m", "pip", "install", "-e", os.environ["GLOBUS_SDK_PATH"]])'
coverage run -m pytest {posargs}
depends =
py{3.12,3.11,3.10,3.9,3.8}{,-mindeps}: clean
cov-combine: py{3.12,3.11,3.10,3.9,3.8}{,-mindeps}
py{3.13,3.12,3.11,3.10,3.9,3.8}{,-mindeps}: clean
cov-combine: py{3.13,3.12,3.11,3.10,3.9,3.8}{,-mindeps}
cov-report: cov-combine

[testenv:clean]
Expand Down Expand Up @@ -74,16 +74,14 @@ skip_install = true
commands = pre-commit run --all-files

[testenv:mypy]
base_python =
python3.12
python3.11
python3.10
deps =
mypy==1.10.1
types-jwt
types-requests
types-jmespath
dependency_groups = typing
commands = mypy {posargs:src/}
[testenv:mypy-minpython]
base = mypy
commands = mypy --python-version "3.8" {posargs:src/}
[testenv:mypy-maxpython]
base = mypy
commands = mypy --python-version "3.13" {posargs:src/}

[testenv:reference]
allowlist_externals = find
Expand Down

0 comments on commit 39d7110

Please sign in to comment.