Skip to content

Commit 8975bd7

Browse files
committed
repo: Add strict to zip calls
By default, if iterables passed to zip have different lengths, the resulting iterator will be silently truncated to the length of the shortest. The `strict` argument was introduced in Python 3.10 and should be explicit for all zip function calls. This is also verified with the flake8-bugbear linter checks in ruff. Signed-off-by: Pieter De Gendt <[email protected]>
1 parent d93e8b6 commit 8975bd7

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

tests/test_manifest.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ def test_project_revisions():
393393
''')
394394
expected = [Project('p1', 'u1', revision='defaultrev'),
395395
Project('p2', 'u2', revision='rev')]
396-
for p, e in zip(m.projects[1:], expected):
396+
for p, e in zip(m.projects[1:], expected, strict=True):
397397
check_proj_consistency(p, e)
398398

399399
# The default revision, if not given in a defaults section, is
@@ -776,7 +776,7 @@ def test_self_tag():
776776
Project('testproject2', 'https://example2.com/testproject2')]
777777

778778
# Check the projects are as expected.
779-
for p, e in zip(m.projects, expected):
779+
for p, e in zip(m.projects, expected, strict=True):
780780
check_proj_consistency(p, e)
781781

782782
# With a "self: path:" value, that will be available in the
@@ -1726,7 +1726,7 @@ def test_import_basics(content):
17261726
revision='segger-upstream-rev',
17271727
path='modules/debug/segger')]
17281728

1729-
for a, e in zip(actual, expected):
1729+
for a, e in zip(actual, expected, strict=True):
17301730
check_proj_consistency(a, e)
17311731

17321732
def test_import_with_fork_and_proj():
@@ -1766,7 +1766,7 @@ def test_import_with_fork_and_proj():
17661766
revision='segger-upstream-rev',
17671767
path='modules/debug/segger')]
17681768

1769-
for a, e in zip(actual, expected):
1769+
for a, e in zip(actual, expected, strict=True):
17701770
check_proj_consistency(a, e)
17711771

17721772
def test_import_project_list(manifest_repo):
@@ -1815,7 +1815,7 @@ def test_import_project_list(manifest_repo):
18151815
Project('p2', 'p2-url', topdir=topdir),
18161816
Project('p3', 'p3-url', topdir=topdir)]
18171817

1818-
for a, e in zip(actual, expected):
1818+
for a, e in zip(actual, expected, strict=True):
18191819
check_proj_consistency(a, e)
18201820

18211821
def test_import_project_directory(manifest_repo):
@@ -1867,7 +1867,7 @@ def test_import_project_directory(manifest_repo):
18671867
Project('p2', 'p2-url', topdir=topdir),
18681868
Project('p3', 'p3-url', topdir=topdir)]
18691869

1870-
for a, e in zip(actual, expected):
1870+
for a, e in zip(actual, expected, strict=True):
18711871
check_proj_consistency(a, e)
18721872

18731873
def test_import_project_err_malformed(manifest_repo):
@@ -2211,7 +2211,7 @@ def test_import_self_directory(content, tmp_workspace):
22112211
assert [a.name for a in actual] == [e.name for e in expected]
22122212

22132213
# With the basic check done, do a more detailed check.
2214-
for a, e in zip(actual, expected):
2214+
for a, e in zip(actual, expected, strict=True):
22152215
check_proj_consistency(a, e)
22162216

22172217
def test_import_self_bool():
@@ -2674,7 +2674,7 @@ def test_import_path_prefix_basics(manifest_repo):
26742674
path='prefix/2/not-cloned-2', topdir=topdir),
26752675
Project('not-cloned-3', 'https://example.com/not-cloned-3',
26762676
path='pre/fix/3/not-cloned-3', topdir=topdir)]
2677-
for a, e in zip(actual, expected):
2677+
for a, e in zip(actual, expected, strict=True):
26782678
check_proj_consistency(a, e)
26792679

26802680
def test_import_path_prefix_self(manifest_repo):
@@ -2760,7 +2760,7 @@ def test_import_path_prefix_propagation(manifest_repo):
27602760
Project('project-2', 'https://example.com/project-2',
27612761
path='prefix/1/prefix-2/project-2',
27622762
topdir=topdir)]
2763-
for a, e in zip(actual, expected):
2763+
for a, e in zip(actual, expected, strict=True):
27642764
check_proj_consistency(a, e)
27652765

27662766
def test_import_path_prefix_no_escape(manifest_repo):

tests/test_project.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def _list_f(format):
9292

9393

9494
def _match_multiline_regex(expected, actual):
95-
for eline_re, aline in zip(expected, actual):
95+
for eline_re, aline in zip(expected, actual, strict=True):
9696
assert re.match(eline_re, aline) is not None, (aline, eline_re)
9797

9898

@@ -2374,7 +2374,7 @@ def test_import_project_release(repos_tmpdir):
23742374
Project('net-tools', remotes / 'net-tools',
23752375
clone_depth=1, topdir=ws,
23762376
west_commands='scripts/west-commands.yml')]
2377-
for a, e in zip(actual, expected):
2377+
for a, e in zip(actual, expected, strict=True):
23782378
check_proj_consistency(a, e)
23792379

23802380
# Add a commit in the remote zephyr repository and make sure it
@@ -2389,7 +2389,7 @@ def test_import_project_release(repos_tmpdir):
23892389

23902390
assert head_before == rev_parse(zephyr_ws, 'HEAD')
23912391
actual = Manifest.from_topdir(topdir=ws).projects
2392-
for a, e in zip(actual, expected):
2392+
for a, e in zip(actual, expected, strict=True):
23932393
check_proj_consistency(a, e)
23942394
assert (zephyr_ws / 'should-not-clone').check(file=0)
23952395

@@ -2443,7 +2443,7 @@ def test_import_project_release_fork(repos_tmpdir):
24432443
Project('net-tools', remotes / 'net-tools',
24442444
clone_depth=1, topdir=ws,
24452445
west_commands='scripts/west-commands.yml')]
2446-
for a, e in zip(actual, expected):
2446+
for a, e in zip(actual, expected, strict=True):
24472447
check_proj_consistency(a, e)
24482448

24492449
zephyr_ws = ws / 'zephyr'
@@ -2455,7 +2455,7 @@ def test_import_project_release_fork(repos_tmpdir):
24552455

24562456
assert head_before == rev_parse(zephyr_ws, 'HEAD')
24572457
actual = Manifest.from_topdir(topdir=ws).projects
2458-
for a, e in zip(actual, expected):
2458+
for a, e in zip(actual, expected, strict=True):
24592459
check_proj_consistency(a, e)
24602460
assert (zephyr_ws / 'should-not-clone').check(file=0)
24612461

@@ -2514,7 +2514,7 @@ def test_import_project_release_dir(tmpdir):
25142514
Project('west.d_1.yml-p1', empty_project, topdir=ws),
25152515
Project('west.d_1.yml-p2', empty_project, topdir=ws),
25162516
Project('west.d_2.yml-p1', empty_project, topdir=ws)]
2517-
for a, e in zip(actual, expected):
2517+
for a, e in zip(actual, expected, strict=True):
25182518
check_proj_consistency(a, e)
25192519

25202520
def test_import_project_rolling(repos_tmpdir):
@@ -2557,7 +2557,7 @@ def test_import_project_rolling(repos_tmpdir):
25572557
Project('net-tools', remotes / 'net-tools',
25582558
clone_depth=1, topdir=ws,
25592559
west_commands='scripts/west-commands.yml')]
2560-
for a, e in zip(actual, expected):
2560+
for a, e in zip(actual, expected, strict=True):
25612561
check_proj_consistency(a, e)
25622562

25632563
# Add a commit in the remote zephyr repository and make sure it

0 commit comments

Comments
 (0)