Skip to content

Commit

Permalink
Merge pull request #903 from sirosen/more-mypy
Browse files Browse the repository at this point in the history
Minor mypy refinement: one more module is strict
  • Loading branch information
sirosen authored Dec 6, 2023
2 parents 5a9155d + 4f5c801 commit a89dfe0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
3 changes: 0 additions & 3 deletions mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ disallow_untyped_defs = false
[mypy-globus_cli.parsing.param_types.endpoint_plus_path]
disallow_untyped_defs = false

[mypy-globus_cli.parsing.param_types.identity_type]
disallow_untyped_defs = false

[mypy-globus_cli.parsing.shared_options]
disallow_untyped_defs = false

Expand Down
16 changes: 11 additions & 5 deletions src/globus_cli/parsing/param_types/identity_type.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import base64
import uuid
from collections import namedtuple
Expand All @@ -11,7 +13,7 @@ class _B32DecodeError(ValueError):
"""custom exception type"""


def _b32decode(v):
def _b32decode(v: str) -> str:
# should start with "u_"
if not v.startswith("u_"):
raise _B32DecodeError("should start with 'u_'")
Expand Down Expand Up @@ -45,14 +47,18 @@ class IdentityType(click.ParamType):

name = "IDENTITY"

def __init__(self, allow_domains=False, allow_b32_usernames=False):
def __init__(
self, allow_domains: bool = False, allow_b32_usernames: bool = False
) -> None:
self.allow_domains = allow_domains
self.allow_b32_usernames = allow_b32_usernames

def get_type_annotation(self, param: click.Parameter) -> type:
return ParsedIdentity

def convert(self, value, param, ctx):
def convert(
self, value: str, param: click.Parameter | None, ctx: click.Context | None
) -> ParsedIdentity:
# uuid format -> identity
try:
uuid.UUID(value)
Expand Down Expand Up @@ -81,11 +87,11 @@ def convert(self, value, param, ctx):

self.fail(f"'{value}' does not appear to be a valid identity", param=param)

def get_metavar(self, param):
def get_metavar(self, param: click.Parameter) -> str:
return self.metavar

@property
def metavar(self):
def metavar(self) -> str:
if self.allow_domains:
return "IDENTITY_OR_DOMAIN"
else:
Expand Down

0 comments on commit a89dfe0

Please sign in to comment.