Skip to content

Commit b4d168e

Browse files
Improve the type annotation of empty container initializations (#1447)
* Improve the type annotation of empty container initializations This mostly comes up when using the accumulator pattern. Toward #1332 * Revert difficult change (to placate `ty`) Also clarify the importance of static checks in the `usethis-qa-static-checks` skill
1 parent 5fe0bc4 commit b4d168e

26 files changed

Lines changed: 61 additions & 52 deletions

File tree

.agents/skills/usethis-qa-static-checks/SKILL.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ description: Perform static code checks
44
compatibility: usethis, Python, prek, basedpyright
55
license: MIT
66
metadata:
7-
version: "1.1"
7+
version: "1.2
88
---
99
1010
# Static Checks
@@ -15,3 +15,9 @@ To perform static checks on the codebase, run:
1515
uv run prek run -a
1616
uv run basedpyright
1717
```
18+
19+
Note that we are interested in both errors and warnings from these tools - we should always fix both.
20+
21+
## When to run these checks:
22+
23+
Before submitting changes for review, **always** run these static checks. This should be done every time, even for small changes, to avoid slowing down the code review process unnecessarily.

src/usethis/_backend/uv/deps.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,6 @@ def get_default_groups_via_uv() -> list[str]:
4747
PyprojectTOMLManager()[["tool", "uv", "default-groups"]]
4848
)
4949
except (KeyError, ValidationError):
50-
default_groups = []
50+
default_groups: list[str] = []
5151

5252
return default_groups

src/usethis/_backend/uv/python.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def get_supported_uv_minor_python_versions() -> list[PythonVersion]:
2626
except (MissingRequiresPythonError, PyprojectTOMLNotFoundError):
2727
return [PythonVersion.from_interpreter()]
2828

29-
versions = set()
29+
versions: set[str] = set()
3030
for version in get_available_uv_python_versions():
3131
# N.B. a standard range won't include alpha versions.
3232
if requires_python.contains(version):

src/usethis/_core/status.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def use_development_status(
2525
mgr[["project", "classifiers"]]
2626
)
2727
except (KeyError, ValidationError):
28-
existing_classifiers = []
28+
existing_classifiers: list[str] = []
2929
existing_status_classifiers = {
3030
classifier
3131
for classifier in existing_classifiers

src/usethis/_deps.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ def register_default_group(group: str) -> None:
120120
default_groups = get_default_groups()
121121

122122
# Choose which groups we want to add
123-
groups_to_add = []
123+
groups_to_add: list[str] = []
124124
if group not in default_groups:
125125
groups_to_add.append(group)
126126
# Add "dev" if section is empty or if we're adding a new group and "dev" isn't present

src/usethis/_file/ini/io_.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ def __delitem__(self, keys: Sequence[Key]) -> None:
356356
elif len(keys) == 2:
357357
(section_key, option_key) = keys
358358

359-
section_strkeys = []
359+
section_strkeys: list[str] = []
360360
for section_strkey in _itermatches(self.get().sections(), key=section_key):
361361
section_strkeys.append(section_strkey)
362362

src/usethis/_file/pyproject_toml/requires_python.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def get_required_minor_python_versions() -> list[PythonVersion]:
7777
# always deal with just major version 3 in practice.
7878
min_minor_in_spec = min(all_minors)
7979

80-
supported_versions = []
80+
supported_versions: list[PythonVersion] = []
8181
# Generate all major.minor combinations in range
8282
# Basically, do a sophisticated brute-force search
8383
for major in range(min_version[0], max_version[0] + 1):
@@ -101,7 +101,7 @@ def get_required_minor_python_versions() -> list[PythonVersion]:
101101

102102
# Get patch versions mentioned for this major.minor in the specifier
103103
# The extremes will lie +/- 1 from any named patch version
104-
patches_to_check = set()
104+
patches_to_check: set[int] = set()
105105
major_minor_key = (major, minor)
106106
if major_minor_key in patches_by_short:
107107
for patch in patches_by_short[major_minor_key]:

src/usethis/_file/yaml/update.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,11 @@ def _shared_id_sequences(*seqs: Sequence[object]) -> Sequence[list[int]]:
127127
# we can store this information as a list of elements, where the index corresponds
128128
# to the integer representation.
129129

130-
iseqs = []
131-
rep = []
130+
iseqs: list[list[int]] = []
131+
rep: list[object] = []
132132

133133
for seq in seqs:
134-
iseq = []
134+
iseq: list[int] = []
135135
for element in seq:
136136
for idx, rep_element in enumerate(rep):
137137
if element == rep_element:

src/usethis/_integrations/ci/bitbucket/pipeweld.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def get_pipeweld_pipeline_from_default(
3636
default = model.pipelines.default
3737

3838
if default is None:
39-
items = []
39+
items: list[schema.StepItem | schema.ParallelItem | schema.StageItem] = []
4040
elif isinstance(default.root, schema.ImportPipeline):
4141
msg = (
4242
"Cannot add step to default pipeline in 'bitbucket-pipelines.yml' because "
@@ -117,7 +117,7 @@ def apply_pipeweld_instruction_via_model(
117117
default = pipelines.default
118118

119119
if default is None:
120-
items = []
120+
items: list[schema.StepItem | schema.ParallelItem | schema.StageItem] = []
121121
elif isinstance(default.root, schema.ImportPipeline):
122122
msg = (
123123
f"Cannot add step '{step_to_insert.name}' to default pipeline in "

src/usethis/_integrations/ci/bitbucket/steps.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ def _censor_stage_item_step(
375375
) -> schema.StageItem | None:
376376
step1s = item.stage.steps
377377

378-
new_step1s = []
378+
new_step1s: list[schema.Step1] = []
379379
for step1 in step1s:
380380
if bitbucket_steps_are_equivalent(step1tostep(step1), step):
381381
continue
@@ -474,7 +474,7 @@ def _get_steps_in_pipeline(pipeline: schema.Pipeline) -> list[schema.Step]:
474474

475475
items = pipeline.root.root
476476

477-
steps = []
477+
steps: list[schema.Step] = []
478478
for item in items:
479479
steps.extend(get_steps_in_pipeline_item(item))
480480

0 commit comments

Comments
 (0)