Commit 7b3f2f3
committed
Widen nested_type Callable branch on introspection failure
Closes #673.
The Callable branch of `nested_type` could raise on three real values
where the documented `Box(type(value))` fallback was expected:
- `pytest.mark.parametrize` (a `MarkDecorator`): `typing.get_overloads`
raises `AttributeError` because `MarkDecorator` lacks `__qualname__`.
- `dict.get` (a `method_descriptor`): same shape — missing `__module__`.
- An `Operation` wrapping a callable with a stringified annotation that
does not resolve in scope: `inspect.signature` consults
`Operation.__signature__`, which calls `typing.get_type_hints`, which
raises `NameError`.
Per the canonicalize-widening principle (eb8680 on PR #613): when
introspection cannot construct a more precise `TypeExpression`, the
right move is to widen rather than propagate the failure.
- Wrap `typing.get_overloads(value)` and `inspect.signature(value)`
with broader `except` clauses (adding `AttributeError`, `TypeError`,
`NameError`) that fall back to `Box(type(value))`.
- The `Operation` branch propagates the widening when its Callable
delegate returns a bare type rather than a parameterised one.
Adds three regression tests pinning each failure mode.1 parent d226d10 commit 7b3f2f3
2 files changed
Lines changed: 63 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
962 | 962 | | |
963 | 963 | | |
964 | 964 | | |
965 | | - | |
| 965 | + | |
| 966 | + | |
| 967 | + | |
| 968 | + | |
| 969 | + | |
| 970 | + | |
966 | 971 | | |
967 | 972 | | |
968 | 973 | | |
969 | 974 | | |
970 | 975 | | |
971 | | - | |
| 976 | + | |
| 977 | + | |
| 978 | + | |
| 979 | + | |
| 980 | + | |
| 981 | + | |
| 982 | + | |
| 983 | + | |
| 984 | + | |
972 | 985 | | |
973 | 986 | | |
| 987 | + | |
| 988 | + | |
| 989 | + | |
| 990 | + | |
| 991 | + | |
| 992 | + | |
| 993 | + | |
| 994 | + | |
974 | 995 | | |
975 | 996 | | |
976 | | - | |
| 997 | + | |
977 | 998 | | |
978 | 999 | | |
979 | 1000 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
867 | 867 | | |
868 | 868 | | |
869 | 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 | + | |
870 | 909 | | |
871 | 910 | | |
872 | 911 | | |
| |||
0 commit comments