Skip to content

Commit

Permalink
feat: add types for PEP 735
Browse files Browse the repository at this point in the history
Signed-off-by: Henry Schreiner <[email protected]>
  • Loading branch information
henryiii committed Oct 11, 2024
1 parent 5f49b28 commit e2c6526
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion pyproject_metadata/project_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from __future__ import annotations

import sys
from typing import Any, Dict, List, Union
from typing import TYPE_CHECKING, Any, Dict, List, Union

if sys.version_info < (3, 11):
from typing_extensions import Required
Expand All @@ -28,6 +28,7 @@
"BuildSystemTable",
"ContactTable",
"Dynamic",
"IncludeGroupTable",
"LicenseTable",
"ProjectTable",
"PyProjectTable",
Expand Down Expand Up @@ -107,12 +108,46 @@ class LicenseTable(TypedDict, total=False):
total=False,
)

# total=False here because this could be
# extended in the future
IncludeGroupTable = TypedDict(
"IncludeGroupTable",
{"include-group": str},
total=False,
)

PyProjectTable = TypedDict(
"PyProjectTable",
{
"build-system": BuildSystemTable,
"project": ProjectTable,
"tool": Dict[str, Any],
"dependency-groups": Dict[str, List[Union[str, IncludeGroupTable]]],
},
total=False,
)

# Tests for type checking
if TYPE_CHECKING:
PyProjectTable(

Check warning on line 132 in pyproject_metadata/project_table.py

View check run for this annotation

Codecov / codecov/patch

pyproject_metadata/project_table.py#L132

Added line #L132 was not covered by tests
{
"build-system": BuildSystemTable(
{"build-backend": "one", "requires": ["two"]}
),
"project": ProjectTable(
{
"name": "one",
"version": "0.1.0",
}
),
"tool": {"thing": object()},
"dependency-groups": {
"one": [
"one",
IncludeGroupTable({"include-group": "two"}),
]
},
}
)


0 comments on commit e2c6526

Please sign in to comment.