Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ Unreleased
- Remove support for Python 3.8
- Correct the type of the ``dependency_groups`` parameter to ``resolve()``,
``resolve_all()``, and ``DependencyGroupsResolver()``.
- Raise a clear ``TypeError`` when an ``include-group`` value is not a string
(was a cryptic ``TypeError`` from name normalization), and accept any
``Mapping`` for include items, not only ``dict``.

1.3.1
-----
Expand Down
6 changes: 5 additions & 1 deletion src/dependency_groups/_implementation.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,15 @@ def _parse_group(
# valid PEP 508 Dependency Specifier
# raises InvalidRequirement on failure
elements.append(Requirement(item))
elif isinstance(item, dict):
elif isinstance(item, Mapping):
if tuple(item.keys()) != ("include-group",):
raise ValueError(f"Invalid dependency group item: {item}")

include_group = next(iter(item.values()))
if not isinstance(include_group, str):
raise TypeError(
f"Invalid include-group value, must be a string: {item}"
)
elements.append(DependencyGroupInclude(include_group=include_group))
else:
raise ValueError(f"Invalid dependency group item: {item}")
Expand Down
21 changes: 21 additions & 0 deletions tests/test_resolve_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,27 @@ def test_unknown_object_shape(item):
resolve(groups, "test")


def test_non_str_include_group_value():
groups = {"test": [{"include-group": 5}]}
with pytest.raises(
TypeError, match="Invalid include-group value, must be a string:"
):
resolve(groups, "test")


def test_mapping_include_group_item():
import types

groups = {
"test": [
"pytest",
types.MappingProxyType({"include-group": "runtime"}),
],
"runtime": ["sqlalchemy"],
}
assert set(resolve(groups, "test")) == {"pytest", "sqlalchemy"}


def test_resolve_all_empty():
groups = {}
assert resolve_all(groups) == {}
Expand Down