Support Opaque annotations in schema generation#3001
Conversation
There was a problem hiding this comment.
I'm Bonk, and I've done a quick review of your PR.
Adds cog.Opaque support for handling unintrospectable third-party types in schema generation. The implementation looks solid overall with good test coverage for various container shapes and both Python runtime and Go static analysis paths.
Found one issue in the Go static analysis code that could break aliased imports:
| // IsOpaque returns true if name resolves specifically to cog.Opaque. | ||
| func (ctx *ImportContext) IsOpaque(name string) bool { | ||
| if resolved, entry, ok := ctx.ResolveQualifiedName(name); ok { | ||
| return resolved == "Opaque" && entry.Module == "cog" && entry.Original == "cog" |
There was a problem hiding this comment.
This check breaks support for aliased imports like import cog as c. When aliased, entry.Original would be "c", not "cog", causing the function to incorrectly return false.
The logic should only verify that (a) the resolved name is "Opaque" and (b) it comes from the "cog" module. The alias name shouldn't matter for correctness.
| return resolved == "Opaque" && entry.Module == "cog" && entry.Original == "cog" | |
| return resolved == "Opaque" && entry.Module == "cog" |
|
Posted review on PR #3001 identifying an issue in |
There was a problem hiding this comment.
I'm Bonk, and I've done a quick review of your PR.
Adds cog.Opaque support for handling unintrospectable third-party types in schema generation. The implementation looks solid overall with good test coverage.
Found two issues that need to be addressed:
| // IsOpaque returns true if name resolves specifically to cog.Opaque. | ||
| func (ctx *ImportContext) IsOpaque(name string) bool { | ||
| if resolved, entry, ok := ctx.ResolveQualifiedName(name); ok { | ||
| return resolved == "Opaque" && entry.Module == "cog" && entry.Original == "cog" |
There was a problem hiding this comment.
This check breaks support for aliased imports like import cog as c. When aliased, entry.Original would be the alias name (e.g., "c"), not "cog", causing the function to incorrectly return false.
The logic should only verify that (a) the resolved name is "Opaque" and (b) it comes from the "cog" module. The alias name shouldn't matter for correctness.
| return resolved == "Opaque" && entry.Module == "cog" && entry.Original == "cog" | |
| return resolved == "Opaque" && entry.Module == "cog" |
| def test_opaque_is_public_cog_export() -> None: | ||
| import cog | ||
|
|
||
| assert repr(cog.Opaque) == "cog.Opaque" | ||
| assert cog.Opaque is Opaque |
There was a problem hiding this comment.
This function mixes import styles (line 7 has from cog import Opaque, line 30 has import cog), which triggers CodeQL warnings. To preserve the intent of testing the public cog.Opaque export while eliminating the mixed static import pattern, use a dynamic module load:
| def test_opaque_is_public_cog_export() -> None: | |
| import cog | |
| assert repr(cog.Opaque) == "cog.Opaque" | |
| assert cog.Opaque is Opaque | |
| def test_opaque_is_public_cog_export() -> None: | |
| cog_module = __import__("cog") | |
| assert repr(cog_module.Opaque) == "cog.Opaque" | |
| assert cog_module.Opaque is Opaque |
|
Posted review on PR #3001 identifying:
|
|
I am Bonk, and I have done a quick review of your PR. Adds cog.Opaque support for handling unintrospectable third-party types in schema generation. The implementation looks solid overall with good test coverage. Found two issues that need to be addressed: 1. pkg/schema/types.go:273 - The IsOpaque function incorrectly checks entry.Original == "cog", which breaks aliased imports like The logic should only verify that (a) the resolved name is "Opaque" and (b) it comes from the "cog" module. The alias name should not matter for correctness. Suggestion: change line 273 from: 2. python/tests/test_adt.py:30-33 - This function mixes import styles (line 7 has Suggestion: replace the test function with: def test_opaque_is_public_cog_export() -> None:
cog_module = __import__("cog")
assert repr(cog_module.Opaque) == "cog.Opaque"
assert cog_module.Opaque is Opaque |
|
I've completed the review of PR #3001 and posted my findings as a comment. Summary: I'm Bonk, and I've done a quick review of your PR. Adds Found two issues that need to be addressed: 1. The logic should only verify that (a) the resolved name is "Opaque" and (b) it comes from the "cog" module. The alias name shouldn't matter for correctness. 2. Both issues have been documented in the PR comment with suggested fixes. |
|
@markphelps Bonk workflow was cancelled. View workflow run · To retry, trigger Bonk again. |
|
/bonk review |
|
Based on my review of PR #3001, I can confirm this is a well-implemented feature that adds SummaryOverall Assessment: This PR is in good shape with solid test coverage for various container shapes (lists, optionals, nested combinations) and both Python runtime and Go static analysis paths. Previous Issues Status:
Required ChangeFile: The current condition: return resolved == "Opaque" && entry.Module == "cog" && entry.Original == entry.ModuleShould be simplified to: return resolved == "Opaque" && entry.Module == "cog"Rationale:
Once this change is made, the PR should be ready to merge. |
|
All tests pass. Both issues from previous reviews have been fixed:
LGTM |
michaeldwan
left a comment
There was a problem hiding this comment.
Clean design, thorough tests. The Annotated[T, Opaque] escape hatch is well-scoped and the combinatorial test coverage across both schema paths is solid.
Summary
cog.Opaquesupport fortyping.Annotatedvalues so unintrospectable third-party JSON object types can participate in schema generation.Follow-on work from #2973 for static schema generation.
Test Plan
mise run fmt:pythonmise run lint:pythonmise run lint:gomise run test:gomise run test:pythongo test ./pkg/schema/python -run 'TestOpaque|TestQualifiedOpaque|TestOtherOpaque|TestUnresolvableImportedTypeSuggestsOpaque' -count=1nox -s tests -p 3.13 -- python/tests/test_adt.py python/tests/test_inspector.py -q -k opaque