Skip to content

Commit 105cf21

Browse files
More fixes for Pyright.
1 parent b925fde commit 105cf21

7 files changed

Lines changed: 68 additions & 78 deletions

File tree

apps/bfd-model-idr/augment_sample_resources.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,8 @@ def create_rendering_line_provider(npi_num):
261261
matching_rows = cond_sk_df[cond_sk_df["CLM_RLT_COND_SGNTR_SK"] == str(cond_sk)]
262262
for _, row in matching_rows.iterrows():
263263
cond_cd = row.get("CLM_RLT_COND_CD")
264-
if pd.notna(cond_cd) and str(cond_cd) != "~":
264+
# Use manual NaN check instead of pd.isna()
265+
if cond_cd is not None and cond_cd == cond_cd and str(cond_cd) != "~":
265266
supporting_info_components.append({"CLM_RLT_COND_CD": str(cond_cd)})
266267

267268
fac_type = cur_sample_data.get("CLM_BILL_FAC_TYPE_CD")

apps/bfd-pipeline-idr/extractor.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,14 @@
3232
IDR_WAREHOUSE,
3333
MIN_BATCH_COMPLETION_DATE,
3434
)
35-
from timer import Timer
35+
from .timer import Timer
36+
from typing import Iterator, Sequence
37+
from model.base_model import IdrBaseModel
38+
from abc import ABC, abstractmethod
3639

3740
logger = logging.getLogger(__name__)
3841

39-
40-
class Extractor[T](ABC):
42+
class Extractor[T: IdrBaseModel](ABC):
4143
def __init__(self, cls: type[T], partition: LoadPartition) -> None:
4244
self.cls = cls
4345
self.type_adapter = TypeAdapter(list[self.cls])
@@ -66,10 +68,7 @@ def _greatest_col(self, cols: list[str]) -> str:
6668

6769
def _get_batch_size(self) -> int:
6870
if ENABLE_DATE_PARTITIONS:
69-
# Larger tables take up more memory, so we'll try to normalize
70-
# the total memory used here based on the number of columns
7171
return round(BATCH_MULTIPLIER / len(self.cls.columns_raw()))
72-
# If date partitioning is not enabled, the number of concurrent jobs will be small
7372
return 100_000
7473

7574
def get_query(self, start_time: datetime, load_mode: LoadMode) -> str:
@@ -83,15 +82,15 @@ def extract_idr_data(
8382
) -> Iterator[Sequence[T]]:
8483
is_historical = progress is None or progress.is_historical()
8584
fetch_query = self.get_query(start_time, load_mode)
86-
# GREATEST doesn't work with nulls so we need to coalesce here
8785
batch_timestamp_cols = self._coalesce_dates(
8886
self.cls.batch_timestamp_col_alias(is_historical)
8987
)
9088
update_timestamp_cols = self._coalesce_dates(self.cls.update_timestamp_col_alias())
91-
# We need to create batches using the most recent timestamp from all of the
92-
# insert/update timestamps
9389
batch_timestamp_clause = self._greatest_col([*batch_timestamp_cols, *update_timestamp_cols])
94-
min_transaction_date = self.cls.model_type().min_transaction_date
90+
91+
# Fix: defer type checking for dynamic model_type()
92+
model_instance = self.cls.model_type() # type: ignore[call-arg]
93+
min_transaction_date = model_instance.min_transaction_date
9594

9695
batch_id_order = ""
9796
batch_id_clause = ""
@@ -101,7 +100,6 @@ def extract_idr_data(
101100
logger.info("extracting %s", self.cls.table())
102101
order_by = f"ORDER BY {batch_timestamp_clause} {batch_id_order}"
103102
if progress is None:
104-
# No saved progress, process the whole table from the beginning
105103
return self.extract_many(
106104
fetch_query.replace(
107105
"{WHERE_CLAUSE}",

apps/bfd-pipeline-idr/loader.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
bfd_db_username,
1818
force_load_progress,
1919
)
20-
from timer import Timer
20+
from .timer import Timer
2121

2222
logger = logging.getLogger(__name__)
2323

apps/utils/locust_tests/common/bfd_user_base.py

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
from common.validation import ValidationResult
1717
from locust import FastHttpUser, events
1818
from locust.argument_parser import LocustArgumentParser
19-
from locust.contrib.fasthttp import ResponseContextManager
2019
from locust.env import Environment
2120

2221
_COMPARISONS_METADATA_PATH = None
@@ -188,11 +187,7 @@ def get_by_url(
188187
catch_response=True,
189188
) as response:
190189
if response.status_code != 200:
191-
if isinstance(response, ResponseContextManager):
192-
# pylint: disable=E1121
193-
response.failure(f"Status Code: {response.status_code}")
194-
else:
195-
response.failure()
190+
response.failure(f"Status Code: {response.status_code}")
196191
elif response.text:
197192
# Check for valid "next" URLs that we can add to a URL pool.
198193
next_url = BFDUserBase.__get_next_url(response.text)
@@ -226,11 +221,7 @@ def post_by_url(
226221
catch_response=True,
227222
) as response:
228223
if response.status_code != 200:
229-
if isinstance(response, ResponseContextManager):
230-
# pylint: disable=E1121
231-
response.failure(f"Status Code: {response.status_code}")
232-
else:
233-
response.failure()
224+
response.failure(f"Status Code: {response.status_code}")
234225
elif response.text:
235226
# Check for valid "next" URLs that we can add to a URL pool.
236227
next_url = BFDUserBase.__get_next_url(response.text)

apps/utils/locust_tests/services/server-load/controller/controller.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,20 +93,19 @@ def _start_node(
9393

9494
return response
9595

96-
9796
def _main() -> None:
9897
try:
9998
cluster_id = get_ssm_parameter(
100-
ssm_client=ssm_client,
99+
ssm_client=ssm_client, # type: ignore[arg-type]
101100
name=f"/bfd/{environment}/common/nonsensitive/rds_cluster_identifier",
102101
)
103102
username = get_ssm_parameter(
104-
ssm_client=ssm_client,
103+
ssm_client=ssm_client, # type: ignore[arg-type]
105104
name=f"/bfd/{environment}/server/sensitive/db/username",
106105
with_decrypt=True,
107106
)
108107
raw_password = get_ssm_parameter(
109-
ssm_client=ssm_client,
108+
ssm_client=ssm_client, # type: ignore[arg-type]
110109
name=f"/bfd/{environment}/server/sensitive/db/password",
111110
with_decrypt=True,
112111
)

pyproject.toml

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@ requires-python="==3.14.3"
55
description = "BFD Python workspace for unified dependency management"
66

77
dependencies = [
8+
"tqdm",
89
"psycopg[binary,pool]>=3.2.13",
910
"pydantic==2.13.3",
1011
# sftp-outbound-transfer dependencies
1112
"aws-lambda-powertools[all]",
1213
"paramiko",
1314
"boto3",
15+
"types-boto3>=1.43.2",
1416
"aiohttp>=3.13.0",
1517
"asyncclick>=8.3.0.5",
1618
"anyio>=4.11.0",
@@ -46,7 +48,6 @@ members = [
4648

4749
[dependency-groups]
4850
dev = [
49-
"tqdm",
5051
"ruff",
5152
"pyright",
5253
# bfd-pipeline-idr dev dependencies
@@ -123,6 +124,7 @@ docstring-code-format = true
123124
typeCheckingMode = "strict"
124125
venvPath = "."
125126
venv = ".venv"
127+
# TODO: Move these downstream for lambdas with powertools only:
126128
reportMissingImports = false
127129
reportMissingTypeStubs = "none"
128130
# AWS Lambda Powertools compatibility - relaxed type checking for ops services
@@ -138,18 +140,15 @@ exclude = [
138140
"**/.venv",
139141
"**/node_modules",
140142
"**/__pycache__",
141-
# "**/bfd-model-idr/**",
143+
"apps/utils/locust_tests/v1/**",
144+
"apps/utils/locust_tests/v2/**",
142145
"**/bfd-model-rif/**",
143-
"**/bfd-pipeline-idr/**",
144-
# "**/locust_tests/**",
145-
# "**/synthetic-load-converter/**",
146-
# "**/sftp_outbound_transfer/**",
147146
"apps/bfd-model/**",
148147
"apps/bfd-pipeline/**",
149148
"apps/bfd-server/**",
150-
"apps/utils/**",
149+
"ops/utils/synthetic-data/**",
150+
"ops/services/02-insights-bb2/**",
151151
"docs/**",
152-
"ops/**",
153152
"insights/**",
154153
"src/**",
155154
"static-site/**",

0 commit comments

Comments
 (0)