Commit 96ccfd4
* feat(types): widen extension-point list[X] to Sequence[X] for adopter inheritance
Closes #624.
Adopters who follow Critical Pattern #1 (subclass a library response
type and override a parent's `list[X]` field with `list[ChildX]`) hit
`# type: ignore[assignment]` on every override under mypy --strict —
list is invariant in its element type. Sequence is covariant, so a
Sequence[Parent] parent permits list[Child] override (where Child <:
Parent) cleanly.
This PR adds a post-codegen processor (`widen_extension_point_lists_to_sequence`
in `scripts/post_generate_fixes.py`) that rewrites annotations on a
small allowlist of fields documented as extension points. The allowlist
is keyed on (file, class, field) so it survives codegen reformatting
and field-order drift.
The current allowlist contains one confirmed entry —
`UpdateMediaBuyResponse.affected_packages` (matches salesagent
`_base.py:360`) — across the two emitted variants
(`media_buy/` and `bundled/media_buy/`). Nine TODO entries are
placeholders pending the salesagent `# type: ignore[assignment]` line
list — fill in as they're mapped.
`tests/type_checks/extend_response_with_sequence.py` is the regression
gate: subclasses `UpdateMediaBuyResponse1` with an overridden
`affected_packages: list[_InternalPackage]` and asserts mypy --strict
accepts the override with zero ignores.
The Pydantic plugin behavior was validated in a 2-file spike before
this PR — see the comment on #624 for the validation result.
BREAKING CHANGE: callers passing `affected_packages` into a function
typed `def f(x: list[Package])` will see a mypy error and need to
migrate to `Sequence[Package]`. Runtime behavior is unchanged; the
change is annotation-only.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* feat(types): expand #624 allowlist with full Category A entries
Refactor allowlist from (file, class, field) to (class, field) tuples
and walk every generated .py file. datamodel-codegen emits bundled
response files that each inline copies of subordinate types
(Placement, TargetingOverlay, etc.); the walker rewrites every
emission so all paths stay consistent.
Allowlist now covers all 15 Category A entries:
- Response: UpdateMediaBuyResponse.affected_packages,
GetMediaBuyDeliveryResponse.media_buy_deliveries,
GetCreativeDeliveryResponse.creatives, Signal.deployments,
GetSignalsResponse.signals, GetMediaBuysResponse.media_buys,
ListCreativesResponse.creatives
- Request: PackageRequest.creatives, CreateMediaBuyRequest.packages,
UpdateMediaBuyRequest.packages
- Cross-cutting: Placement.format_ids, TargetingOverlay.geo_*_exclude (4)
Result: 47 fields widened across 21 generated files. Pairs that
match zero files emit a WARN so allowlist drift surfaces fast.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* fix(types): address pre-merge review on #624 — bound regex to class, silent idempotency, document scope
Three fixes from expert review:
1. Regex now bounded to current class. _widen_field_annotation slices
region up to next ^class before running the field search. Latent
bug fix — current corpus has no collisions, but prevents future
codegen changes from silently triggering it.
2. Idempotent re-runs are silent. New _field_already_widened helper
tracks "already Sequence" separately from "no list found"; WARN
fires only when neither is found anywhere (genuine drift).
3. Regression test scope honestly documented. Required-field overrides
surface a separate codegen multi-emission issue (filed as #642):
datamodel-codegen emits Creative/Package/etc. per response file, so
public alias resolves to one emission while parent field references
another. Test docstring documents the scope.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 3160ace commit 96ccfd4
24 files changed
Lines changed: 393 additions & 50 deletions
File tree
- scripts
- src/adcp/types/generated_poc
- bundled
- creative
- media_buy
- signals
- core
- creative
- media_buy
- signals
- tests/type_checks
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
799 | 799 | | |
800 | 800 | | |
801 | 801 | | |
| 802 | + | |
| 803 | + | |
| 804 | + | |
| 805 | + | |
| 806 | + | |
| 807 | + | |
| 808 | + | |
| 809 | + | |
| 810 | + | |
| 811 | + | |
| 812 | + | |
| 813 | + | |
| 814 | + | |
| 815 | + | |
| 816 | + | |
| 817 | + | |
| 818 | + | |
| 819 | + | |
| 820 | + | |
| 821 | + | |
| 822 | + | |
| 823 | + | |
| 824 | + | |
| 825 | + | |
| 826 | + | |
| 827 | + | |
| 828 | + | |
| 829 | + | |
| 830 | + | |
| 831 | + | |
| 832 | + | |
| 833 | + | |
| 834 | + | |
| 835 | + | |
| 836 | + | |
| 837 | + | |
| 838 | + | |
| 839 | + | |
| 840 | + | |
| 841 | + | |
| 842 | + | |
| 843 | + | |
| 844 | + | |
| 845 | + | |
| 846 | + | |
| 847 | + | |
| 848 | + | |
| 849 | + | |
| 850 | + | |
| 851 | + | |
| 852 | + | |
| 853 | + | |
| 854 | + | |
| 855 | + | |
| 856 | + | |
| 857 | + | |
| 858 | + | |
| 859 | + | |
| 860 | + | |
| 861 | + | |
| 862 | + | |
| 863 | + | |
| 864 | + | |
| 865 | + | |
| 866 | + | |
| 867 | + | |
| 868 | + | |
| 869 | + | |
| 870 | + | |
| 871 | + | |
| 872 | + | |
| 873 | + | |
| 874 | + | |
| 875 | + | |
| 876 | + | |
| 877 | + | |
| 878 | + | |
| 879 | + | |
| 880 | + | |
| 881 | + | |
| 882 | + | |
| 883 | + | |
| 884 | + | |
| 885 | + | |
| 886 | + | |
| 887 | + | |
| 888 | + | |
| 889 | + | |
| 890 | + | |
| 891 | + | |
| 892 | + | |
| 893 | + | |
| 894 | + | |
| 895 | + | |
| 896 | + | |
| 897 | + | |
| 898 | + | |
| 899 | + | |
| 900 | + | |
| 901 | + | |
| 902 | + | |
| 903 | + | |
| 904 | + | |
| 905 | + | |
| 906 | + | |
| 907 | + | |
| 908 | + | |
| 909 | + | |
| 910 | + | |
| 911 | + | |
| 912 | + | |
| 913 | + | |
| 914 | + | |
| 915 | + | |
| 916 | + | |
| 917 | + | |
| 918 | + | |
| 919 | + | |
| 920 | + | |
| 921 | + | |
| 922 | + | |
| 923 | + | |
| 924 | + | |
| 925 | + | |
| 926 | + | |
| 927 | + | |
| 928 | + | |
| 929 | + | |
| 930 | + | |
| 931 | + | |
| 932 | + | |
| 933 | + | |
| 934 | + | |
| 935 | + | |
| 936 | + | |
| 937 | + | |
| 938 | + | |
| 939 | + | |
| 940 | + | |
| 941 | + | |
| 942 | + | |
| 943 | + | |
| 944 | + | |
| 945 | + | |
| 946 | + | |
| 947 | + | |
| 948 | + | |
| 949 | + | |
| 950 | + | |
| 951 | + | |
| 952 | + | |
| 953 | + | |
| 954 | + | |
| 955 | + | |
| 956 | + | |
| 957 | + | |
| 958 | + | |
| 959 | + | |
| 960 | + | |
| 961 | + | |
| 962 | + | |
| 963 | + | |
| 964 | + | |
| 965 | + | |
| 966 | + | |
| 967 | + | |
| 968 | + | |
| 969 | + | |
| 970 | + | |
| 971 | + | |
| 972 | + | |
| 973 | + | |
| 974 | + | |
| 975 | + | |
| 976 | + | |
| 977 | + | |
| 978 | + | |
| 979 | + | |
| 980 | + | |
| 981 | + | |
| 982 | + | |
| 983 | + | |
| 984 | + | |
| 985 | + | |
| 986 | + | |
| 987 | + | |
| 988 | + | |
| 989 | + | |
| 990 | + | |
| 991 | + | |
| 992 | + | |
| 993 | + | |
| 994 | + | |
| 995 | + | |
| 996 | + | |
| 997 | + | |
| 998 | + | |
| 999 | + | |
| 1000 | + | |
| 1001 | + | |
| 1002 | + | |
| 1003 | + | |
| 1004 | + | |
| 1005 | + | |
| 1006 | + | |
| 1007 | + | |
| 1008 | + | |
| 1009 | + | |
| 1010 | + | |
| 1011 | + | |
| 1012 | + | |
| 1013 | + | |
| 1014 | + | |
| 1015 | + | |
| 1016 | + | |
| 1017 | + | |
| 1018 | + | |
| 1019 | + | |
| 1020 | + | |
| 1021 | + | |
| 1022 | + | |
| 1023 | + | |
| 1024 | + | |
| 1025 | + | |
| 1026 | + | |
| 1027 | + | |
| 1028 | + | |
| 1029 | + | |
| 1030 | + | |
| 1031 | + | |
| 1032 | + | |
| 1033 | + | |
| 1034 | + | |
| 1035 | + | |
| 1036 | + | |
| 1037 | + | |
| 1038 | + | |
| 1039 | + | |
| 1040 | + | |
| 1041 | + | |
| 1042 | + | |
| 1043 | + | |
| 1044 | + | |
| 1045 | + | |
| 1046 | + | |
| 1047 | + | |
| 1048 | + | |
| 1049 | + | |
| 1050 | + | |
| 1051 | + | |
| 1052 | + | |
| 1053 | + | |
| 1054 | + | |
| 1055 | + | |
802 | 1056 | | |
803 | 1057 | | |
804 | 1058 | | |
| |||
816 | 1070 | | |
817 | 1071 | | |
818 | 1072 | | |
| 1073 | + | |
819 | 1074 | | |
820 | 1075 | | |
821 | 1076 | | |
| |||
Lines changed: 2 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
| |||
3612 | 3613 | | |
3613 | 3614 | | |
3614 | 3615 | | |
3615 | | - | |
| 3616 | + | |
3616 | 3617 | | |
3617 | 3618 | | |
3618 | 3619 | | |
| |||
Lines changed: 2 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
| |||
3810 | 3811 | | |
3811 | 3812 | | |
3812 | 3813 | | |
3813 | | - | |
| 3814 | + | |
3814 | 3815 | | |
3815 | 3816 | | |
3816 | 3817 | | |
| |||
Lines changed: 6 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
| |||
2576 | 2577 | | |
2577 | 2578 | | |
2578 | 2579 | | |
2579 | | - | |
| 2580 | + | |
2580 | 2581 | | |
2581 | 2582 | | |
2582 | 2583 | | |
| |||
2590 | 2591 | | |
2591 | 2592 | | |
2592 | 2593 | | |
2593 | | - | |
| 2594 | + | |
2594 | 2595 | | |
2595 | 2596 | | |
2596 | 2597 | | |
| |||
2604 | 2605 | | |
2605 | 2606 | | |
2606 | 2607 | | |
2607 | | - | |
| 2608 | + | |
2608 | 2609 | | |
2609 | 2610 | | |
2610 | 2611 | | |
| |||
2618 | 2619 | | |
2619 | 2620 | | |
2620 | 2621 | | |
2621 | | - | |
| 2622 | + | |
2622 | 2623 | | |
2623 | 2624 | | |
2624 | 2625 | | |
| |||
5030 | 5031 | | |
5031 | 5032 | | |
5032 | 5033 | | |
5033 | | - | |
| 5034 | + | |
5034 | 5035 | | |
5035 | 5036 | | |
5036 | 5037 | | |
| |||
Lines changed: 5 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
| |||
2540 | 2541 | | |
2541 | 2542 | | |
2542 | 2543 | | |
2543 | | - | |
| 2544 | + | |
2544 | 2545 | | |
2545 | 2546 | | |
2546 | 2547 | | |
| |||
2554 | 2555 | | |
2555 | 2556 | | |
2556 | 2557 | | |
2557 | | - | |
| 2558 | + | |
2558 | 2559 | | |
2559 | 2560 | | |
2560 | 2561 | | |
| |||
2568 | 2569 | | |
2569 | 2570 | | |
2570 | 2571 | | |
2571 | | - | |
| 2572 | + | |
2572 | 2573 | | |
2573 | 2574 | | |
2574 | 2575 | | |
| |||
2582 | 2583 | | |
2583 | 2584 | | |
2584 | 2585 | | |
2585 | | - | |
| 2586 | + | |
2586 | 2587 | | |
2587 | 2588 | | |
2588 | 2589 | | |
| |||
0 commit comments