Skip to content

Commit f01722a

Browse files
Enable reportUnnecessaryComparison in basedpyright and fix violations
Co-authored-by: nathanjmcdougall <18602289+nathanjmcdougall@users.noreply.github.com>
1 parent b0b821f commit f01722a

4 files changed

Lines changed: 51 additions & 68 deletions

File tree

pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,6 @@ reportUnknownLambdaType = false
226226
reportUnknownMemberType = false
227227
reportUnknownParameterType = false
228228
reportUnknownVariableType = false
229-
reportUnnecessaryComparison = false
230229
reportUnnecessaryIsInstance = false
231230
reportUnusedCallResult = false
232231
reportUnusedParameter = false

src/usethis/_core/readme.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,22 +32,16 @@ def add_readme() -> None:
3232
except PyprojectTOMLError:
3333
project_description = None
3434

35-
if project_name is not None and project_description is not None:
35+
if project_description is not None:
3636
content = f"""\
3737
# {project_name}
3838
3939
{project_description}
4040
"""
41-
elif project_name is not None:
41+
else:
4242
content = f"""\
4343
# {project_name}
4444
"""
45-
elif project_description is not None:
46-
content = f"""\
47-
{project_description}
48-
"""
49-
else:
50-
content = ""
5145

5246
tick_print("Writing 'README.md'.")
5347
(usethis_config.cpd() / "README.md").write_text(content, encoding="utf-8")

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

Lines changed: 47 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -61,16 +61,15 @@ def get_pipeweld_object(
6161
elif isinstance(item, schema.ParallelItem):
6262
parallel_steps: set[str] = set()
6363

64-
if item.parallel is not None:
65-
if isinstance(item.parallel.root, schema.ParallelSteps):
66-
step_items = item.parallel.root.root
67-
elif isinstance(item.parallel.root, schema.ParallelExpanded):
68-
step_items = item.parallel.root.steps.root
69-
else:
70-
assert_never(item.parallel.root)
64+
if isinstance(item.parallel.root, schema.ParallelSteps):
65+
step_items = item.parallel.root.root
66+
elif isinstance(item.parallel.root, schema.ParallelExpanded):
67+
step_items = item.parallel.root.steps.root
68+
else:
69+
assert_never(item.parallel.root)
7170

72-
for step_item in step_items:
73-
parallel_steps.add(get_pipeweld_step(step_item.step))
71+
for step_item in step_items:
72+
parallel_steps.add(get_pipeweld_step(step_item.step))
7473

7574
return usethis._pipeweld.containers.Parallel(frozenset(parallel_steps))
7675
elif isinstance(item, schema.StageItem):
@@ -245,28 +244,27 @@ def _extract_step_from_parallel_item(
245244
items: list[schema.StepItem | schema.ParallelItem | schema.StageItem],
246245
idx: int,
247246
) -> schema.Step | None:
248-
if item.parallel is not None:
249-
if isinstance(item.parallel.root, schema.ParallelSteps):
250-
step_items = item.parallel.root.root
251-
elif isinstance(item.parallel.root, schema.ParallelExpanded):
252-
step_items = item.parallel.root.steps.root
253-
else:
254-
assert_never(item.parallel.root)
255-
256-
for step_idx, step_item in enumerate(step_items):
257-
if get_pipeweld_step(step_item.step) == step_name:
258-
# Found it - remove from the parallel block
259-
extracted_step = step_item.step
260-
step_items.pop(step_idx)
261-
262-
# If only one step remains in the parallel, convert to a simple step
263-
if len(step_items) == 1:
264-
items[idx] = step_items[0]
265-
elif len(step_items) == 0:
266-
# No steps left, remove the parallel item
267-
items.pop(idx)
268-
269-
return extracted_step
247+
if isinstance(item.parallel.root, schema.ParallelSteps):
248+
step_items = item.parallel.root.root
249+
elif isinstance(item.parallel.root, schema.ParallelExpanded):
250+
step_items = item.parallel.root.steps.root
251+
else:
252+
assert_never(item.parallel.root)
253+
254+
for step_idx, step_item in enumerate(step_items):
255+
if get_pipeweld_step(step_item.step) == step_name:
256+
# Found it - remove from the parallel block
257+
extracted_step = step_item.step
258+
step_items.pop(step_idx)
259+
260+
# If only one step remains in the parallel, convert to a simple step
261+
if len(step_items) == 1:
262+
items[idx] = step_items[0]
263+
elif len(step_items) == 0:
264+
# No steps left, remove the parallel item
265+
items.pop(idx)
266+
267+
return extracted_step
270268
return None
271269

272270

@@ -296,17 +294,14 @@ def _insert_parallel_step(
296294
)
297295
items[idx] = parallel_item
298296
elif isinstance(item, schema.ParallelItem):
299-
if item.parallel is not None:
300-
if isinstance(item.parallel.root, schema.ParallelSteps):
301-
# Add to the existing list of parallel steps
302-
item.parallel.root.root.append(schema.StepItem(step=step_to_insert))
303-
elif isinstance(item.parallel.root, schema.ParallelExpanded):
304-
# Add to the expanded parallel steps
305-
item.parallel.root.steps.root.append(
306-
schema.StepItem(step=step_to_insert)
307-
)
308-
else:
309-
assert_never(item.parallel.root)
297+
if isinstance(item.parallel.root, schema.ParallelSteps):
298+
# Add to the existing list of parallel steps
299+
item.parallel.root.root.append(schema.StepItem(step=step_to_insert))
300+
elif isinstance(item.parallel.root, schema.ParallelExpanded):
301+
# Add to the expanded parallel steps
302+
item.parallel.root.steps.root.append(schema.StepItem(step=step_to_insert))
303+
else:
304+
assert_never(item.parallel.root)
310305
elif isinstance(item, schema.StageItem):
311306
# StageItems are trickier since they aren't supported in ParallelSteps. But we
312307
# never need to add them in practice anyway. The only reason this is really here
@@ -324,17 +319,16 @@ def _is_insertion_necessary(
324319
if isinstance(item, schema.StepItem):
325320
return get_pipeweld_step(item.step) == instruction.after
326321
elif isinstance(item, schema.ParallelItem):
327-
if item.parallel is not None:
328-
if isinstance(item.parallel.root, schema.ParallelSteps):
329-
step_items = item.parallel.root.root
330-
elif isinstance(item.parallel.root, schema.ParallelExpanded):
331-
step_items = item.parallel.root.steps.root
332-
else:
333-
assert_never(item.parallel.root)
334-
335-
for step_item in step_items:
336-
if get_pipeweld_step(step_item.step) == instruction.after:
337-
return True
322+
if isinstance(item.parallel.root, schema.ParallelSteps):
323+
step_items = item.parallel.root.root
324+
elif isinstance(item.parallel.root, schema.ParallelExpanded):
325+
step_items = item.parallel.root.steps.root
326+
else:
327+
assert_never(item.parallel.root)
328+
329+
for step_item in step_items:
330+
if get_pipeweld_step(step_item.step) == instruction.after:
331+
return True
338332
return False
339333
elif isinstance(item, schema.StageItem):
340334
step1s = item.stage.steps.copy()

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -495,14 +495,10 @@ def get_steps_in_pipeline_item(
495495
else:
496496
assert_never(_p)
497497

498-
steps = [
499-
step_item.step for step_item in step_items if step_item.step is not None
500-
]
498+
steps = [step_item.step for step_item in step_items]
501499
return steps
502500
elif isinstance(item, schema.StageItem):
503-
return [
504-
step1tostep(step1) for step1 in item.stage.steps if step1.step is not None
505-
]
501+
return [step1tostep(step1) for step1 in item.stage.steps]
506502
else:
507503
assert_never(item)
508504

0 commit comments

Comments
 (0)