[ty] Refine Callable class-decorator fallback for unknown results#25250
Conversation
eefba0b to
b66ba5b
Compare
Typing conformance resultsNo changes detected ✅Current numbersThe percentage of diagnostics emitted that were expected errors held steady at 89.36%. The percentage of expected errors that received a diagnostic held steady at 85.49%. The number of fully passing files held steady at 88/134. |
b66ba5b to
312f04e
Compare
Memory usage reportSummary
Significant changesClick to expand detailed breakdownprefect
trio
sphinx
flake8
|
|
| Lint rule | Added | Removed | Changed |
|---|---|---|---|
invalid-type-form |
0 | 18 | 0 |
unused-type-ignore-comment |
11 | 0 | 0 |
unknown-argument |
0 | 6 | 0 |
invalid-argument-type |
0 | 4 | 0 |
missing-argument |
0 | 4 | 0 |
unresolved-attribute |
0 | 4 | 0 |
invalid-assignment |
0 | 0 | 1 |
no-matching-overload |
0 | 1 | 0 |
| Total | 11 | 37 | 1 |
Raw diff (49 changes)
pandera (https://github.com/pandera-dev/pandera)
- pandera/typing/pandas.py:108:9 error[invalid-type-form] Variable of type `type[Unknown]` is not allowed in a type expression
- pandera/typing/pandas.py:109:9 error[invalid-type-form] Variable of type `type[Unknown]` is not allowed in a type expression
- pandera/typing/pandas.py:110:9 error[invalid-type-form] Variable of type `type[Unknown]` is not allowed in a type expression
- pandera/typing/pandas.py:111:9 error[invalid-type-form] Variable of type `type[Unknown]` is not allowed in a type expression
- pandera/typing/pandas.py:112:9 error[invalid-type-form] Variable of type `type[Unknown]` is not allowed in a type expression
- pandera/typing/pandas.py:113:9 error[invalid-type-form] Variable of type `type[Unknown]` is not allowed in a type expression
- pandera/typing/pandas.py:114:9 error[invalid-type-form] Variable of type `type[Unknown]` is not allowed in a type expression
- pandera/typing/pandas.py:115:9 error[invalid-type-form] Variable of type `type[Unknown]` is not allowed in a type expression
- pandera/typing/pandas.py:116:9 error[invalid-type-form] Variable of type `type[Unknown]` is not allowed in a type expression
+ pandera/typing/pyspark_sql.py:35:29 warning[unused-type-ignore-comment] Unused blanket `type: ignore` directive
+ pandera/typing/pyspark_sql.py:36:26 warning[unused-type-ignore-comment] Unused blanket `type: ignore` directive
+ pandera/typing/pyspark_sql.py:37:30 warning[unused-type-ignore-comment] Unused blanket `type: ignore` directive
+ pandera/typing/pyspark_sql.py:38:31 warning[unused-type-ignore-comment] Unused blanket `type: ignore` directive
+ pandera/typing/pyspark_sql.py:39:30 warning[unused-type-ignore-comment] Unused blanket `type: ignore` directive
+ pandera/typing/pyspark_sql.py:40:29 warning[unused-type-ignore-comment] Unused blanket `type: ignore` directive
+ pandera/typing/pyspark_sql.py:41:28 warning[unused-type-ignore-comment] Unused blanket `type: ignore` directive
+ pandera/typing/pyspark_sql.py:43:27 warning[unused-type-ignore-comment] Unused blanket `type: ignore` directive
+ pandera/typing/pyspark_sql.py:44:32 warning[unused-type-ignore-comment] Unused blanket `type: ignore` directive
+ pandera/typing/pyspark_sql.py:45:29 warning[unused-type-ignore-comment] Unused blanket `type: ignore` directive
- tests/geopandas/test_engine.py:119:20 error[no-matching-overload] No overload of function `any` matches arguments
+ tests/pandas/test_dtypes.py:158:74 warning[unused-type-ignore-comment] Unused blanket `type: ignore` directive
- tests/pandas/test_dtypes.py:176:43 error[invalid-assignment] Object of type `list[tuple[dict[Unknown, Unknown], list[Unknown]] | tuple[dict[<class 'datetime'> | <class 'datetime64'> | type[Unknown] | ... omitted 3 union elements, str], Series[Timestamp]] | tuple[dict[PeriodDtype, str], Series[Period]] | tuple[dict[<class 'SparseDtype'> | SparseDtype, SparseDtype], Series[Any]] | tuple[dict[IntervalDtype, str], Series[Interval[int | float]]]]` is not assignable to `list[tuple[dict[Unknown, Unknown], list[Unknown]]]`
+ tests/pandas/test_dtypes.py:176:43 error[invalid-assignment] Object of type `list[tuple[dict[Unknown, Unknown], list[Unknown]] | tuple[dict[<class 'datetime'> | <class 'datetime64'> | type[Unknown] | DatetimeTZDtype | Unknown, str], Series[Timestamp]] | tuple[dict[PeriodDtype, str], Series[Period]] | tuple[dict[<class 'SparseDtype'> | SparseDtype, SparseDtype], Series[Any]] | tuple[dict[IntervalDtype, str], Series[Interval[int | float]]]]` is not assignable to `list[tuple[dict[Unknown, Unknown], list[Unknown]]]`
- tests/pandas/test_logical_dtypes.py:212:12 error[unresolved-attribute] Object of type `bool | Iterable[bool]` has no attribute `all`
- tests/pandas/test_logical_dtypes.py:235:16 error[unresolved-attribute] Object of type `bool | Iterable[bool]` has no attribute `any`
- tests/pandas/test_logical_dtypes.py:243:31 error[invalid-argument-type] Argument to bound method `Decimal.check` is incorrect: Expected `DataType`, found `dtype[generic[Any]] | ExtensionDtype`
- tests/pandas/test_logical_dtypes.py:245:12 error[unresolved-attribute] Object of type `bool | Iterable[bool]` has no attribute `dtype`
- tests/pandas/test_logical_dtypes.py:269:9 error[invalid-argument-type] Argument to bound method `Decimal.check` is incorrect: Expected `pandera.engines.pandas_engine.DataType`, found `pandera.dtypes.DataType`
- tests/pandas/test_logical_dtypes.py:269:52 error[invalid-argument-type] Argument to bound method `Decimal.check` is incorrect: Expected `Series[Any] | None`, found `Series[Any] | DataFrame`
- tests/pandas/test_logical_dtypes.py:272:12 error[unresolved-attribute] Object of type `bool | Iterable[bool]` has no attribute `all`
- tests/pandas/test_pandas_engine.py:129:24 error[invalid-argument-type] Argument to bound method `DataType.check` is incorrect: Expected `DataType`, found `dtype[generic[Any]] | ExtensionDtype | Series[Any]`
- tests/pandas/test_pandas_engine.py:212:9 error[missing-argument] No argument provided for required parameter `dtype` of `DataType.__init__`
- tests/pandas/test_pandas_engine.py:213:13 error[unknown-argument] Argument `tz` does not match any known parameter of `DataType.__init__`
- tests/pandas/test_pandas_engine.py:213:26 error[unknown-argument] Argument `tz_localize_kwargs` does not match any known parameter of `DataType.__init__`
- tests/pandas/test_pandas_engine.py:376:13 error[unknown-argument] Argument `time_zone_agnostic` does not match any known parameter of `DataType.__init__`
- tests/pandas/test_pandas_engine.py:376:38 error[unknown-argument] Argument `tz` does not match any known parameter of `DataType.__init__`
- tests/pandas/test_pandas_engine.py:375:26 error[missing-argument] No argument provided for required parameter `dtype` of `DataType.__init__`
- tests/pandas/test_typing.py:86:17 error[invalid-type-form] Variable of type `type[Unknown]` is not allowed in a type expression
- tests/pandas/test_typing.py:98:17 error[invalid-type-form] Variable of type `type[Unknown]` is not allowed in a type expression
- tests/pandas/test_typing.py:102:17 error[invalid-type-form] Variable of type `type[Unknown]` is not allowed in a type expression
- tests/pandas/test_typing.py:106:17 error[invalid-type-form] Variable of type `type[Unknown]` is not allowed in a type expression
- tests/pandas/test_typing.py:110:17 error[invalid-type-form] Variable of type `type[Unknown]` is not allowed in a type expression
- tests/pandas/test_typing.py:114:17 error[invalid-type-form] Variable of type `type[Unknown]` is not allowed in a type expression
- tests/pandas/test_typing.py:118:17 error[invalid-type-form] Variable of type `type[Unknown]` is not allowed in a type expression
- tests/pandas/test_typing.py:122:17 error[invalid-type-form] Variable of type `type[Unknown]` is not allowed in a type expression
- tests/pandas/test_typing.py:126:17 error[invalid-type-form] Variable of type `type[Unknown]` is not allowed in a type expression
- tests/pyspark/test_schemas_on_pyspark_pandas.py:280:13 error[missing-argument] No argument provided for required parameter `dtype` of `DataType.__init__`
- tests/pyspark/test_schemas_on_pyspark_pandas.py:280:13 error[missing-argument] No argument provided for required parameter `dtype` of `DataType.__init__`
- tests/pyspark/test_schemas_on_pyspark_pandas.py:280:36 error[unknown-argument] Argument `tz` does not match any known parameter of `DataType.__init__`
- tests/pyspark/test_schemas_on_pyspark_pandas.py:280:36 error[unknown-argument] Argument `tz` does not match any known parameter of `DataType.__init__`48c7c74 to
c276337
Compare
|
|
||
| pub(super) kind: CallableTypeKind, | ||
|
|
||
| pub(crate) provenance: Option<CallableFunctionProvenance>, |
There was a problem hiding this comment.
Most of the changes in this diff are mechanically threading this through so that we don't lose this information at decorator-application time.
There was a problem hiding this comment.
Can you say what does it mean when this field is None?
Is it that if it's Some(...) then this callable is coming from either a function literal, bound method literal or a lambda expression? And, if it's None then it's coming from Callable annotation or a ParamSpec specialization?
There was a problem hiding this comment.
Yes, that's roughly right, but there are other cases where it could be None, e.g., we also use callable when we synthesize methods, and those are also marked as None here since there's no upstream function.
Merging this PR will not alter performance
Comparing Footnotes
|
| /// Whether this callable is known to come from a function and how that function's return type was | ||
| /// declared. | ||
| #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, get_size2::GetSize)] | ||
| pub enum CallableFunctionProvenance { |
There was a problem hiding this comment.
I'm unable to follow where does the "whether this callable is known to come from a function" information is present because the enum members suggests only whether the return type is implicit or explicit.
There was a problem hiding this comment.
I moved the None in here and tried to clarify in the docs.
|
|
||
| pub(super) kind: CallableTypeKind, | ||
|
|
||
| pub(crate) provenance: Option<CallableFunctionProvenance>, |
There was a problem hiding this comment.
Can you say what does it mean when this field is None?
Is it that if it's Some(...) then this callable is coming from either a function literal, bound method literal or a lambda expression? And, if it's None then it's coming from Callable annotation or a ParamSpec specialization?
c276337 to
5300e19
Compare
…tral-sh#25250) ## Summary This PR addresses a TODO from astral-sh#25091 whereby we preserved the class binding for every `Callable` decorator. We now respect explicit return annotations on `Callable`. For example, this now remains a replacement rather than being treated as class-preserving: ```python from typing import Callable, TypeVar T = TypeVar("T") def decorator_factory() -> Callable[[type[object]], T]: raise NotImplementedError @decorator_factory() class Decorated: ... reveal_type(Decorated) # Unknown ```
Summary
This PR addresses a TODO from #25091 whereby we preserved the class binding for every
Callabledecorator. We now respect explicit return annotations on
Callable.For example, this now remains a replacement rather than being treated as class-preserving: