From 76510fc74a4ded1bb5eaf15d587f53a33f3e1112 Mon Sep 17 00:00:00 2001 From: Rita Agarwala Date: Thu, 12 Nov 2026 13:20:00 +0530 Subject: [PATCH 1/2] Dynamic error message instead of static for function signature mistmatch --- src/datacustomcode/cli.py | 6 ++-- src/datacustomcode/constants.py | 7 +++-- src/datacustomcode/deploy.py | 34 ++++++++++++++++----- tests/test_describe_supported_signatures.py | 23 ++++++++++++++ 4 files changed, 58 insertions(+), 12 deletions(-) create mode 100644 tests/test_describe_supported_signatures.py diff --git a/src/datacustomcode/cli.py b/src/datacustomcode/cli.py index 3a03e6d9..e2690a6f 100644 --- a/src/datacustomcode/cli.py +++ b/src/datacustomcode/cli.py @@ -215,6 +215,7 @@ def deploy( COMPUTE_TYPES, CodeExtensionMetadata, deploy_full, + describe_supported_signatures, infer_use_in_feature, ) from datacustomcode.token_provider import ( @@ -252,8 +253,9 @@ def deploy( else: click.secho( "Error: Function signature does not match a supported type. " - "Use SearchIndexChunkingV1Request and " - "SearchIndexChunkingV1Response in function signature.", + "Use a supported Request/Response pair in the function " + "signature. For example, " + f"{describe_supported_signatures(entrypoint_path)}.", fg="red", ) raise click.Abort() diff --git a/src/datacustomcode/constants.py b/src/datacustomcode/constants.py index fe29a5cf..23b139d3 100644 --- a/src/datacustomcode/constants.py +++ b/src/datacustomcode/constants.py @@ -46,8 +46,9 @@ SCRIPT_USE_IN_FEATURE_STREAMING, ] -# Pydantic request/response type names to feature names +# (request type name, response type name) pair to feature name REQUEST_TYPE_TO_FEATURE = { - "SearchIndexChunkingV1Request": "SearchIndexChunking", - "SearchIndexChunkingV1Response": "SearchIndexChunking", + ("SearchIndexChunkingV1Request", "SearchIndexChunkingV1Response"): ( + "SearchIndexChunking" + ), } diff --git a/src/datacustomcode/deploy.py b/src/datacustomcode/deploy.py index 18a4f863..2b57b583 100644 --- a/src/datacustomcode/deploy.py +++ b/src/datacustomcode/deploy.py @@ -95,15 +95,35 @@ def infer_use_in_feature(entrypoint_path: str) -> Union[str, None]: if not request_type_name or not response_type_name: return None - # Look up features for both types - request_feature = REQUEST_TYPE_TO_FEATURE.get(request_type_name) - response_feature = REQUEST_TYPE_TO_FEATURE.get(response_type_name) + return REQUEST_TYPE_TO_FEATURE.get((request_type_name, response_type_name)) - # Both must be present and must match - if request_feature and response_feature and request_feature == response_feature: - return request_feature - return None +def describe_supported_signatures(entrypoint_path: str) -> str: + """Build a contract-mismatch hint based on the function's feature type. + + If the request or response type belongs to a known feature, only that + feature's expected pair is listed; otherwise all supported pairs are. + Each pair is followed by the use_in_feature it maps to, e.g. + ``Req/Resp for use_in_feature: SearchIndexChunking``. + """ + from datacustomcode.function_utils import inspect_function_types_static + + request_type_name, response_type_name = inspect_function_types_static( + entrypoint_path + ) + supported = list(REQUEST_TYPE_TO_FEATURE.items()) + sharing_a_type = [ + ((expected_request, expected_response), feature) + for (expected_request, expected_response), feature in supported + if request_type_name == expected_request + or response_type_name == expected_response + ] + # Narrow the hint only when the detected types point at a single feature + to_show = sharing_a_type if len(sharing_a_type) == 1 else supported + return " or ".join( + f"{expected_request}/{expected_response} for use_in_feature: {feature}" + for (expected_request, expected_response), feature in to_show + ) class CodeExtensionMetadata(BaseModel): diff --git a/tests/test_describe_supported_signatures.py b/tests/test_describe_supported_signatures.py new file mode 100644 index 00000000..767a28a3 --- /dev/null +++ b/tests/test_describe_supported_signatures.py @@ -0,0 +1,23 @@ +from datacustomcode.deploy import describe_supported_signatures + + +def test_describe_supported_signatures(tmp_path): + entrypoint = tmp_path / "entrypoint.py" + chunk_pair = ( + "SearchIndexChunkingV1Request/SearchIndexChunkingV1Response " + "for use_in_feature: SearchIndexChunking" + ) + + def describe(request_type, response_type): + entrypoint.write_text( + f"def function(request: {request_type}, runtime)" + f" -> {response_type}:\n pass\n" + ) + return describe_supported_signatures(str(entrypoint)) + + # A recognised request or response narrows the hint to its own feature + assert describe("SearchIndexChunkingV1Request", "dict") == chunk_pair + assert describe("dict", "SearchIndexChunkingV1Response") == chunk_pair + # Unrecognised types fall back to listing every supported pair + fallback = describe("dict", "dict") + assert fallback == chunk_pair From 8d2fb7c7ea713f43422956119f2af86d0841bee2 Mon Sep 17 00:00:00 2001 From: Rita Agarwala Date: Thu, 12 Nov 2026 15:34:03 +0530 Subject: [PATCH 2/2] Fixing lint error --- pyproject.toml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 2d6938b5..c0e868bc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -87,10 +87,10 @@ warn_unused_configs = true [tool.poetry] include = [ - {path = "src/datacustomcode/templates/**/*"}, - {path = "src/datacustomcode/config.yaml"} + { path = "src/datacustomcode/templates/**/*" }, + { path = "src/datacustomcode/config.yaml" } ] -packages = [{include = "datacustomcode", from = "src"}] +packages = [{ include = "datacustomcode", from = "src" }] version = "0.0.0" [tool.poetry.build] @@ -115,7 +115,7 @@ coverage = ">=7.0.0,<8.0.0" ipykernel = "^6.29.5" mypy = "*" pipreqs = "*" -poetry-dynamic-versioning = {extras = ["plugin"], version = "^1.8.2"} +poetry-dynamic-versioning = { extras = ["plugin"], version = "^1.8.2" } pre-commit = "*" pytest = "*" pytest-cov = "*" @@ -127,7 +127,7 @@ types-requests = "*" [tool.poetry.plugins."poetry.plugin"] [tool.poetry.requires-plugins] -poetry-dynamic-versioning = {version = ">=1.0.0,<2.0.0", extras = ["plugin"]} +poetry-dynamic-versioning = { version = ">=1.0.0,<2.0.0", extras = ["plugin"] } [tool.poetry.scripts] datacustomcode = "datacustomcode.cli:cli" @@ -152,7 +152,6 @@ testpaths = ["tests"] [tool.ruff] fix = true line-length = 88 -target-version = 'py310' lint.ignore = [ # do not assign a lambda expression, use a def 'E731', @@ -211,6 +210,7 @@ lint.select = [ 'RUF', 'S102' ] +target-version = 'py310' [tool.setuptools.package_data] datacustomcode = ["templates/**/*", "config.yaml"]