-
Notifications
You must be signed in to change notification settings - Fork 275
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Start linting the examples folder #1701
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,7 @@ | |
from collections import OrderedDict | ||
from datetime import datetime, timedelta | ||
from pathlib import Path | ||
from typing import Any, Dict | ||
|
||
from securesystemslib.keys import generate_ed25519_key | ||
from securesystemslib.signer import SSlibSigner | ||
|
@@ -48,7 +49,7 @@ | |
from tuf.api.serialization.json import JSONSerializer | ||
|
||
|
||
def _in(days): | ||
def _in(days: float) -> datetime: | ||
"""Adds 'days' to now and returns datetime object w/o microseconds.""" | ||
return datetime.utcnow().replace(microsecond=0) + timedelta(days=days) | ||
|
||
|
@@ -89,8 +90,8 @@ def _in(days): | |
|
||
# Define containers for role objects and cryptographic keys created below. This | ||
# allows us to sign and write metadata in a batch more easily. | ||
roles = {} | ||
keys = {} | ||
roles: Dict[str, Metadata] = {} | ||
keys: Dict[str, Dict[str, Any]] = {} | ||
|
||
|
||
# Targets (integrity) | ||
|
@@ -117,7 +118,7 @@ def _in(days): | |
local_path = Path(__file__).resolve() | ||
target_path = f"{local_path.parts[-2]}/{local_path.parts[-1]}" | ||
|
||
target_file_info = TargetFile.from_file(target_path, local_path) | ||
target_file_info = TargetFile.from_file(target_path, str(local_path)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Was this also flagged by mypy? (Also it is odd, because I remember already casting this to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, |
||
roles["targets"].signed.targets[target_path] = target_file_info | ||
|
||
# Snapshot (consistency) | ||
|
@@ -332,7 +333,7 @@ def _in(days): | |
del roles["targets"].signed.targets[target_path] | ||
|
||
# Increase expiry (delegators should be less volatile) | ||
roles["targets"].expires = _in(365) | ||
roles["targets"].signed.expires = _in(365) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👀 Whoopsi, thanks for catching this! Did mypy detect it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, it did. |
||
|
||
|
||
# Snapshot + Timestamp + Sign + Persist | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Quick question, what is the criterion for a variable name to get type annotated?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's needed if mypy can't figure it out from the context (and mypy is not very advanced in this). So in this case
roles = { "root": root_md }
would have been fine but an empty container needs typingThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it does need annotation when you use containers and personally, I think it's better to define annotations in these cases. It makes it so much easier to understand how the container should be used or is used later.