Skip to content

feat: improve internal typings in manifest#278

Draft
IzaakGough wants to merge 3 commits into
mainfrom
@invertase/improve-internal-typings-in-manifest
Draft

feat: improve internal typings in manifest#278
IzaakGough wants to merge 3 commits into
mainfrom
@invertase/improve-internal-typings-in-manifest

Conversation

@IzaakGough
Copy link
Copy Markdown

@IzaakGough IzaakGough commented Jun 1, 2026

Summary

  • Tighten the internal manifest typing so manifest spec generation no longer falls back to _typing.Any.
  • Replace overly broad container types with explicit manifest value aliases and sequence/mapping handling that still accepts the runtime inputs the manifest code serializes today.

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 used dict[str, _typing.Any], untyped helper inputs, and a narrow list check 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 _params registry type so stored params are typed as Param or SecretParam instead of a generic Expression.

Testing

  • Verified existing CI checks passed on the PR, including format, lint, docs, Analyze, CodeQL, and test (3.10) / test (3.12).

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/firebase_functions/private/manifest.py Outdated
Comment on lines +308 to +315
elif data is None:
return None
elif isinstance(data, _util.Sentinel):
return data
elif isinstance(data, (str, int, float, bool)):
return data
else:
raise TypeError(f"Unsupported manifest spec value: {type(data)!r}")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

With the introduction of the strict TypeError check for unsupported types, common types like tuple or custom mappings (which were previously returned as-is) will now raise a TypeError. Since _Mapping is already imported in this file, we should explicitly handle tuple (converting it to a list) and _Mapping (converting it to a spec dict) to maintain compatibility and robustness.

Suggested change
elif data is None:
return None
elif isinstance(data, _util.Sentinel):
return data
elif isinstance(data, (str, int, float, bool)):
return data
else:
raise TypeError(f"Unsupported manifest spec value: {type(data)!r}")
elif isinstance(data, tuple):
return list(map(_object_to_spec, data))
elif isinstance(data, _Mapping):
return _dict_to_spec(data)
elif data is None:
return None
elif isinstance(data, _util.Sentinel):
return data
elif isinstance(data, (str, int, float, bool)):
return data
else:
raise TypeError(f"Unsupported manifest spec value: {type(data)!r}")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants