From a34508bbc9313de579b5fd130847902f35be6472 Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Fri, 11 Oct 2024 15:10:12 -0400 Subject: [PATCH] feat: add types for PEP 735 Signed-off-by: Henry Schreiner --- pyproject_metadata/project_table.py | 34 +++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/pyproject_metadata/project_table.py b/pyproject_metadata/project_table.py index 84d21df..a92d66d 100644 --- a/pyproject_metadata/project_table.py +++ b/pyproject_metadata/project_table.py @@ -11,6 +11,7 @@ from __future__ import annotations import sys +import typing from typing import Any, Dict, List, Union if sys.version_info < (3, 11): @@ -28,6 +29,7 @@ "BuildSystemTable", "ContactTable", "Dynamic", + "IncludeGroupTable", "LicenseTable", "ProjectTable", "PyProjectTable", @@ -107,12 +109,44 @@ 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 typing.TYPE_CHECKING: + PyProjectTable( + { + "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"}), + ] + }, + } + )