Skip to content

Commit fa5717d

Browse files
authored
treewide: ratchet down typing, move mypy config to pyproject (sigstore#85)
* treewide: ratchet down typing, move mypy config to pyproject Signed-off-by: William Woodruff <william@trailofbits.com> * rekor/client: don't rename kwargs This makes Pydantic unhappy. Signed-off-by: William Woodruff <william@trailofbits.com>
1 parent f2deb98 commit fa5717d

File tree

9 files changed

+49
-36
lines changed

9 files changed

+49
-36
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ lint:
4747
black $(ALL_PY_SRCS) && \
4848
isort $(ALL_PY_SRCS) && \
4949
flake8 $(ALL_PY_SRCS) && \
50-
mypy $(PY_MODULE) test/ \
50+
mypy $(PY_MODULE) \
5151
# TODO: Reenable interrogate
5252
# interrogate -v -c pyproject.toml . && \
5353
# git diff --exit-code

mypy.ini

Lines changed: 0 additions & 13 deletions
This file was deleted.

pyproject.toml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,21 @@ omit = ["sigstore/_cli.py"]
7979
exclude = ["setup.py", "env", "test", "sigstore/_cli.py", "sigstore/_version.py"]
8080
ignore-semiprivate = true
8181
fail-under = 100
82+
83+
[tool.mypy]
84+
allow_redefinition = true
85+
check_untyped_defs = true
86+
disallow_incomplete_defs = true
87+
disallow_untyped_defs = true
88+
ignore_missing_imports = true
89+
no_implicit_optional = true
90+
show_error_codes = true
91+
strict_equality = true
92+
warn_no_return = true
93+
warn_redundant_casts = true
94+
warn_return_any = true
95+
warn_unreachable = true
96+
warn_unused_configs = true
97+
warn_unused_ignores = true
98+
99+
plugins = ["pydantic.mypy"]

sigstore/_cli.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
import logging
1616
from importlib import resources
17+
from typing import BinaryIO, List, Optional
1718

1819
import click
1920

@@ -29,7 +30,7 @@
2930

3031
@click.group()
3132
@click.version_option(version=__version__)
32-
def main():
33+
def main() -> None:
3334
pass
3435

3536

@@ -87,14 +88,14 @@ def main():
8788
required=True,
8889
)
8990
def _sign(
90-
files,
91-
identity_token,
92-
ctfe_pem,
93-
oidc_client_id,
94-
oidc_client_secret,
95-
oidc_issuer,
96-
oidc_disable_ambient_providers,
97-
):
91+
files: List[BinaryIO],
92+
identity_token: Optional[str],
93+
ctfe_pem: BinaryIO,
94+
oidc_client_id: str,
95+
oidc_client_secret: str,
96+
oidc_issuer: str,
97+
oidc_disable_ambient_providers: bool,
98+
) -> None:
9899
# The order of precedence is as follows:
99100
#
100101
# 1) Explicitly supplied identity token
@@ -136,7 +137,12 @@ def _sign(
136137
@click.argument(
137138
"files", metavar="FILE [FILE ...]", type=click.File("rb"), nargs=-1, required=True
138139
)
139-
def _verify(files, certificate_path, signature_path, cert_email):
140+
def _verify(
141+
files: List[BinaryIO],
142+
certificate_path: BinaryIO,
143+
signature_path: BinaryIO,
144+
cert_email: Optional[str],
145+
) -> None:
140146
# Load the signing certificate
141147
logger.debug(f"Using certificate from: {certificate_path.name}")
142148
certificate = certificate_path.read()

sigstore/_internal/fulcio/_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def __init__(self, b64_encoded_sct: str):
122122
self.signature: bytes = digitally_signed[4:]
123123

124124
@property
125-
def version(self):
125+
def version(self) -> Version:
126126
return self._version
127127

128128
@property

sigstore/_internal/oidc/oauth.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import urllib.parse
2222
import uuid
2323
import webbrowser
24-
from typing import Dict, List, Optional, cast
24+
from typing import Any, Dict, List, Optional, cast
2525

2626
import requests
2727

@@ -40,10 +40,10 @@
4040

4141

4242
class RedirectHandler(http.server.BaseHTTPRequestHandler):
43-
def log_message(self, format, *args):
43+
def log_message(self, _format: str, *_args: Any) -> None:
4444
pass
4545

46-
def do_GET(self):
46+
def do_GET(self) -> None:
4747
server = cast(RedirectServer, self.server)
4848
r = urllib.parse.urlsplit(self.path)
4949

@@ -56,7 +56,7 @@ def do_GET(self):
5656
self.end_headers()
5757
self.wfile.write(body)
5858
server.auth_response = urllib.parse.parse_qs(r.query)
59-
return
59+
return None
6060

6161
# Any other request generates an auth request
6262
url = server.auth_request()

sigstore/_internal/rekor/_client.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ class RekorEntry:
4141
raw_data: dict
4242

4343
@classmethod
44-
def from_response(cls, dict_) -> RekorEntry:
44+
def from_response(cls, dict_: Dict[str, Any]) -> RekorEntry:
4545
# Assumes we only get one entry back
4646
entries = list(dict_.items())
4747
if len(entries) != 1:
48-
raise RekorClientError("Recieved multiple entries in response")
48+
raise RekorClientError("Received multiple entries in response")
4949

5050
uuid, entry = entries[0]
5151

@@ -67,19 +67,21 @@ class RekorInclusionProof(BaseModel):
6767
hashes: List[str] = Field(..., alias="hashes")
6868

6969
@validator("log_index")
70-
def log_index_positive(cls, v):
70+
def log_index_positive(cls, v: int) -> int:
7171
if v < 0:
7272
raise ValueError(f"Inclusion proof has invalid log index: {v} < 0")
7373
return v
7474

7575
@validator("tree_size")
76-
def tree_size_positive(cls, v):
76+
def tree_size_positive(cls, v: int) -> int:
7777
if v < 0:
7878
raise ValueError(f"Inclusion proof has invalid tree size: {v} < 0")
7979
return v
8080

8181
@validator("tree_size")
82-
def log_index_within_tree_size(cls, v, values, **kwargs):
82+
def log_index_within_tree_size(
83+
cls, v: int, values: Dict[str, Any], **kwargs: Any
84+
) -> int:
8385
if v <= values["log_index"]:
8486
raise ValueError(
8587
"Inclusion proof has log index greater than or equal to tree size: "

sigstore/_internal/set.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
from cryptography.exceptions import InvalidSignature
2525
from cryptography.hazmat.primitives import hashes
2626
from cryptography.hazmat.primitives.serialization import load_pem_public_key
27-
from securesystemslib.formats import encode_canonical # type: ignore
27+
from securesystemslib.formats import encode_canonical
2828

2929
from sigstore._internal.rekor import RekorEntry
3030

sigstore/_verify.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
class VerificationResult(BaseModel):
5757
success: bool
5858

59-
def __bool__(self):
59+
def __bool__(self) -> bool:
6060
return self.success
6161

6262

0 commit comments

Comments
 (0)