Skip to content

Commit

Permalink
Rewrite code to avoid disabling B909
Browse files Browse the repository at this point in the history
  • Loading branch information
DimitriPapadopoulos committed Aug 27, 2024
1 parent 8f1a1d6 commit 1e523c1
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions backend/src/hatchling/metadata/spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,24 +169,27 @@ def project_metadata_from_core_metadata(core_metadata: str) -> dict[str, Any]:
continue

markers = req.marker._markers # noqa: SLF001
index = -1
for i, marker in enumerate(markers):
if isinstance(marker, tuple):
left, _, right = marker
if left.value == 'extra':
extra = right.value
del markers[i] # noqa: B909
# If there was only one marker then there will be an unnecessary
# trailing semicolon in the string representation
if not markers:
req.marker = None
# Otherwise we need to remove the preceding `and` operation
else:
del markers[i - 1]

optional_dependencies.setdefault(extra, []).append(str(req))
index = i
break
else:
dependencies.append(str(req))
if index >= 0:
del markers[index]
index -= 1
# We need to remove the preceding `and` operation...
if index >= 0:
del markers[index]
# ...unless there was only one marker, in which case there will be
# an unnecessary trailing semicolon in the string representation.
else:
req.marker = None

metadata['dependencies'] = dependencies

Expand Down

0 comments on commit 1e523c1

Please sign in to comment.