Skip to content

Commit 9114668

Browse files
committed
pylock: preserve distinction between absent and empty extras and depdency-groups
The specs says these fields are optional with default = []. But it also says "Tools SHOULD explicitly set this key to an empty array to signal that the inputs used to generate the lock file had no dependency groups (e.g. a pyproject.toml file had no [dependency-groups] table), signalling that the lock file is, in effect, multi-use even if it only looks to be single-use.", implying that the distinction between absent and empty is meaningful.
1 parent 11143fd commit 9114668

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

src/pip/_internal/models/pylock.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def _toml_dict_factory(data: List[Tuple[str, Any]]) -> Dict[str, Any]:
8383
return {
8484
_toml_key(key): _toml_value(key, value)
8585
for key, value in data
86-
if value is not None and value != []
86+
if value is not None
8787
}
8888

8989

@@ -544,9 +544,9 @@ class Pylock:
544544
lock_version: Version
545545
environments: Optional[Sequence[Marker]] # = None
546546
requires_python: Optional[SpecifierSet] # = None
547-
extras: Sequence[str] # = dataclasses.field(default_factory=list)
548-
dependency_groups: Sequence[str] # = dataclasses.field(default_factory=list)
549-
default_groups: Sequence[str] # = dataclasses.field(default_factory=list)
547+
extras: Optional[Sequence[str]] # = None
548+
dependency_groups: Optional[Sequence[str]] # = None
549+
default_groups: Optional[Sequence[str]] # = None
550550
created_by: str
551551
packages: Sequence[Package]
552552
tool: Optional[Mapping[str, Any]] = None
@@ -568,9 +568,9 @@ def __init__(
568568
object.__setattr__(self, "lock_version", lock_version)
569569
object.__setattr__(self, "environments", environments)
570570
object.__setattr__(self, "requires_python", requires_python)
571-
object.__setattr__(self, "extras", extras or [])
572-
object.__setattr__(self, "dependency_groups", dependency_groups or [])
573-
object.__setattr__(self, "default_groups", default_groups or [])
571+
object.__setattr__(self, "extras", extras)
572+
object.__setattr__(self, "dependency_groups", dependency_groups)
573+
object.__setattr__(self, "default_groups", default_groups)
574574
object.__setattr__(self, "created_by", created_by)
575575
object.__setattr__(self, "packages", packages)
576576
object.__setattr__(self, "tool", tool)
@@ -592,9 +592,9 @@ def from_dict(cls, d: Mapping[str, Any]) -> "Self":
592592
return cls(
593593
lock_version=_get_required_as(d, str, Version, "lock-version"),
594594
environments=_get_list_as(d, str, Marker, "environments"),
595-
extras=_get_list(d, str, "extras") or [],
596-
dependency_groups=_get_list(d, str, "dependency-groups") or [],
597-
default_groups=_get_list(d, str, "default-groups") or [],
595+
extras=_get_list(d, str, "extras"),
596+
dependency_groups=_get_list(d, str, "dependency-groups"),
597+
default_groups=_get_list(d, str, "default-groups"),
598598
created_by=_get_required(d, str, "created-by"),
599599
requires_python=_get_as(d, str, SpecifierSet, "requires-python"),
600600
packages=_get_required_list_of_objects(d, Package, "packages"),

0 commit comments

Comments
 (0)