feat: improve internal typings in manifest#278
Conversation
There was a problem hiding this comment.
Code Review
This pull request improves type safety in manifest.py by introducing strict type definitions (ManifestParamBase, SpecValue, etc.) and refactoring helper functions to use them. Two critical issues were identified in the review: first, using a generic alias (list[ManifestParamBase]) as a default_factory in ManifestStack will raise a runtime TypeError; second, the new strict type checking in _object_to_spec will raise a TypeError for previously supported types like tuple and custom mappings, which should be explicitly handled.
|
@IzaakGough nice cleanup, the typing is much tighter. A few things to address: We can dismiss both gemini flags:
The new Which is the main ask: the diff is untested. Headline coverage is 91% but every line you changed behavior on is uncovered. Please add tests like these, a unit test documenting the guard plus a real-path test driving the actual API so we know it doesn't bite: class TestObjectToSpec:
def test_unsupported_type_raises(self):
with pytest.raises(TypeError, match="Unsupported manifest spec value"):
_manifest._object_to_spec({"value"})
def test_zoneinfo_converts_to_key(self):
assert _manifest._object_to_spec(ZoneInfo("America/New_York")) == "America/New_York"
class TestStrictSpecInPractice:
def test_schedule_zoneinfo_timezone_builds_without_raising(self):
import firebase_functions.options as _options
options = _options.ScheduleOptions(
schedule="every 5 minutes",
timezone=_options.Timezone("America/New_York"),
)
endpoint = options._endpoint(func_name="test")
spec = _manifest._dataclass_to_spec(endpoint)
assert spec["scheduleTrigger"]["timeZone"] == "America/New_York" |
cabljac
left a comment
There was a problem hiding this comment.
nice direction, see comments
Summary
_typing.Any.Problem/Root Cause
Issue #31 called out that the manifest internals still relied on
_typing.Any, which left the manifest serialization path loosely typed even though it operates on a constrained set of values. The previous implementation useddict[str, _typing.Any], untyped helper inputs, and a narrowlistcheck in_object_to_spec, so type information was lost across manifest parameter conversion and dataclass serialization.Solution/Changes
This change introduces explicit aliases for supported manifest parameter types and manifest spec values, then threads those types through the manifest conversion helpers. The serialization path now distinguishes dataclass instances, mappings, and non-string sequences, which preserves support for inputs such as tuples while keeping the output normalized to manifest-compatible lists and dicts. It also updates the shared
_paramsregistry type so stored params are typed asParamorSecretParaminstead of a genericExpression.Testing
format,lint,docs,Analyze,CodeQL, andtest (3.10)/test (3.12).