Skip to content

Commit 6fd2b31

Browse files
committed
replace mypy with ty
1 parent 7f82e7a commit 6fd2b31

File tree

11 files changed

+360
-407
lines changed

11 files changed

+360
-407
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ permissions:
1212
contents: read
1313

1414
env:
15-
PREK_VERSION: '0.2.13'
15+
PREK_VERSION: '0.2.22'
1616

1717
jobs:
1818
prek:

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
repos:
22
- repo: https://github.com/rhysd/actionlint
3-
rev: v1.7.8
3+
rev: v1.7.9
44
hooks:
55
- id: actionlint-docker
66
- repo: https://github.com/astral-sh/ruff-pre-commit
7-
rev: v0.14.3
7+
rev: v0.14.10
88
hooks:
99
- id: ruff-check
1010
files: ^(cloudsplaining/|setup.py)

cloudsplaining/command/download.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def get_account_authorization_details(
8181
session_data: dict[str, str], include_non_default_policy_versions: bool
8282
) -> dict[str, list[Any]]:
8383
"""Runs aws-iam-get-account-authorization-details"""
84-
session = boto3.Session(**session_data) # type:ignore[arg-type]
84+
session = boto3.Session(**session_data) # ty: ignore[invalid-argument-type]
8585
config = Config(connect_timeout=5, retries={"max_attempts": 10})
8686
iam_client: IAMClient = session.client("iam", config=config)
8787

cloudsplaining/command/scan_multi_account.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,13 +217,13 @@ def scan_accounts(
217217
)
218218
# Write the HTML file
219219
output_file = f"{target_account_name}.html"
220-
s3.Object(output_bucket, output_file).put(ACL="bucket-owner-full-control", Body=rendered_report)
220+
s3.Object(output_bucket, output_file).put(ACL="bucket-owner-full-control", Body=rendered_report) # ty: ignore[unresolved-attribute]
221221
utils.print_green(f"Saved the HTML report to: s3://{output_bucket}/{output_file}")
222222
# Write the JSON data file
223223
if write_data_file:
224224
output_file = f"{target_account_name}.json"
225225
body = json.dumps(results, sort_keys=True, default=str, indent=4)
226-
s3.Object(output_bucket, output_file).put(ACL="bucket-owner-full-control", Body=body)
226+
s3.Object(output_bucket, output_file).put(ACL="bucket-owner-full-control", Body=body) # ty: ignore[unresolved-attribute]
227227
utils.print_green(f"Saved the JSON data to: s3://{output_bucket}/{output_file}")
228228
if output_directory:
229229
# Write the HTML file

cloudsplaining/scan/assume_role_policy_document.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def __init__(
4040
self.policy = policy
4141
self.current_account_id = current_account_id
4242
# We would actually need to define a proper base class with a generic type for statements
43-
self.statements: list[AssumeRoleStatement] = [] # type:ignore[assignment]
43+
self.statements: list[AssumeRoleStatement] = []
4444
self.exclusions = exclusions
4545
# leaving here but excluding from tests because IAM Policy grammar dictates that it must be a list
4646
if not isinstance(statement_structure, list): # pragma: no cover

cloudsplaining/shared/aws_login.py

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,7 @@
2020
def get_boto3_client(service: str, profile: str | None = None, region: str = "us-east-1") -> BaseClient:
2121
"""Get a boto3 client for a given service"""
2222
logging.getLogger("botocore").setLevel(logging.CRITICAL)
23-
session_data = {"region_name": region}
24-
if profile:
25-
session_data["profile_name"] = profile
26-
session = boto3.Session(**session_data) # type:ignore[arg-type]
23+
session = boto3.Session(region_name=region, profile_name=profile)
2724

2825
config = Config(connect_timeout=5, retries={"max_attempts": 10})
2926
if os.environ.get("LOCALSTACK_ENDPOINT_URL"):
@@ -41,10 +38,7 @@ def get_boto3_client(service: str, profile: str | None = None, region: str = "us
4138
def get_boto3_resource(service: str, profile: str | None = None, region: str = "us-east-1") -> ServiceResource:
4239
"""Get a boto3 resource for a given service"""
4340
logging.getLogger("botocore").setLevel(logging.CRITICAL)
44-
session_data = {"region_name": region}
45-
if profile:
46-
session_data["profile_name"] = profile
47-
session = boto3.Session(**session_data) # type:ignore[arg-type]
41+
session = boto3.Session(region_name=region, profile_name=profile)
4842

4943
config = Config(connect_timeout=5, retries={"max_attempts": 10})
5044
resource: ServiceResource = session.resource(service, config=config)
@@ -82,11 +76,7 @@ def get_target_account_credentials(
8276
:param target_account_id: The target account ID
8377
:return:
8478
"""
85-
default_region = "us-east-1"
86-
session_data = {"region_name": default_region}
87-
if profile:
88-
session_data["profile_name"] = profile
89-
session = boto3.Session(**session_data) # type:ignore[arg-type]
79+
session = boto3.Session(region_name="us-east-1", profile_name=profile)
9080
config = Config(connect_timeout=5, retries={"max_attempts": 10})
9181
sts_client: STSClient = session.client("sts", config=config)
9282

cloudsplaining/shared/validation.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,12 @@ def check(conf_schema: Schema, conf: dict[str, list[Any]]) -> bool:
4646
try:
4747
conf_schema.validate(conf)
4848
return True
49-
except SchemaError as schema_error:
49+
except SchemaError as schema_error: # pragma: no cover
5050
try:
5151
# workarounds for Schema's logging approach
5252
print(schema_error.autos[0])
5353
detailed_error_message = schema_error.autos[2]
54-
print(detailed_error_message.split(" in {'")[0]) # pragma: no cover
54+
print(detailed_error_message.split(" in {'")[0]) # ty: ignore[possibly-missing-attribute]
5555
# for error in schema_error.autos:
5656
except Exception:
5757
logger.critical(schema_error)

examples/jira-tickets/open_jira_ticket.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from jira import JIRA
1+
from jira import JIRA # ty: ignore[unresolved-import]
22
import click
33
import getpass
44

justfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ test-js: install-js
4747

4848
[group('test')]
4949
type-check:
50-
mypy
50+
ty check
5151

5252
[group('test')]
5353
unit-tests:

pyproject.toml

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ dependencies = [
2828
"click>=8.1.0,<9.0.0",
2929
"click_option_group>=0.5.9,<0.6.0",
3030
"jinja2>=3.1.0,<4.0.0",
31-
"policy_sentry>=0.14.0,<0.15",
31+
"policy_sentry>=0.15.0,<0.16.0",
3232
"pyyaml>=6.0.0,<7.0.0",
3333
"schema>=0.7.0,<0.8.0",
3434
]
@@ -48,12 +48,12 @@ Twitter = "https://twitter.com/kmcquade3"
4848
[dependency-groups]
4949
dev = [
5050
"boto3-stubs-lite[iam,s3,sts]>=1.40.0,<2.0.0",
51-
"coverage>=7.11.0,<8.0.0",
51+
"coverage>=7.13.0,<8.0.0",
5252
"moto[sts]>=5.1.0,<6.0.0",
53-
"mypy>=1.18.0,<2.0.0",
54-
"prek>=0.2.13,<0.3.0",
55-
"pytest>=8.4.0,<9.0.0",
56-
"rust-just>=1.43.0,<2.0.0",
53+
"prek>=0.2.22,<0.3.0",
54+
"pytest>=9.0.0,<10.0.0",
55+
"rust-just>=1.45.0,<2.0.0",
56+
"ty>=0.0.4,<0.1.0",
5757
"types-pyyaml>=6.0.12,<7.0.0",
5858
]
5959

@@ -85,23 +85,6 @@ module-name = "cloudsplaining"
8585
module-root = ""
8686
source-include = ["test/**"]
8787

88-
[tool.mypy]
89-
files = "cloudsplaining"
90-
91-
python_version = "3.10" # should be identical to the minimum supported version
92-
local_partial_types = true # will become the new default from version 2
93-
allow_redefinition_new = true # will become the new default from version 2
94-
fixed_format_cache = true # new caching mechanism
95-
strict = true
96-
pretty = true
97-
disallow_untyped_decorators = false
98-
99-
[[tool.mypy.overrides]]
100-
module = [
101-
"schema",
102-
]
103-
ignore_missing_imports = true
104-
10588
[tool.ruff]
10689
line-length = 120
10790
target-version = "py310"
@@ -175,3 +158,12 @@ omit = [
175158
"cloudsplaining/output/html_report.py",
176159
"cloudsplaining/output/triage_worksheet.py",
177160
]
161+
162+
[tool.ty.environment]
163+
python-version = "3.10"
164+
165+
[tool.ty.src]
166+
include = ["examples", "cloudsplaining", "utils"]
167+
168+
[tool.ty.rules]
169+
unused-ignore-comment = "error"

0 commit comments

Comments
 (0)