dangotbanned commented on code in PR #47609:
URL: https://github.com/apache/arrow/pull/47609#discussion_r2426056272


##########
python/pyproject.toml:
##########
@@ -83,11 +83,61 @@ include = ["pyarrow"]
 namespaces = false
 
 [tool.setuptools.package-data]
-pyarrow = ["*.pxd", "*.pyx", "includes/*.pxd"]
+pyarrow = ["*.pxd", "*.pyx", "includes/*.pxd", "py.typed"]
 
 [tool.setuptools_scm]
 root = '..'
 version_file = 'pyarrow/_generated_version.py'
 version_scheme = 'guess-next-dev'
 git_describe_command = 'git describe --dirty --tags --long --match 
"apache-arrow-[0-9]*.*"'
 fallback_version = '22.0.0a0'
+
+[tool.mypy]
+files = ["pyarrow"]
+exclude = 'pyarrow/interchange/.*|pyarrow/vendored/.*'
+mypy_path = "$MYPY_CONFIG_FILE_DIR/pyarrow-stubs"
+
+[tool.pyright]
+include = ["pyarrow"]

Review Comment:
   Was just reminded of this issue in `pyarrow-stubs` 
(https://github.com/narwhals-dev/narwhals/pull/3203#issuecomment-3397078247)
   
   ```suggestion
   pythonPlatform = "All"
   pythonVersion = "3.9"
   include = ["pyarrow"]
   ```
   
   The problem with not addressing it at the source, is that the errors 
propagate downstream to anyone that enables the setting 
   
   I'm counting only 4 of these *not* being `pyarrow-stubs` 😳 
   
   <details><summary>Show 113 errors</summary>
   <p>
   
   ```py
   narwhals/_arrow/dataframe.py
     narwhals/_arrow/dataframe.py:447:20 - error: Variable not allowed in type 
expression (reportInvalidTypeForm)
     narwhals/_arrow/dataframe.py:448:38 - error: Variable not allowed in type 
expression (reportInvalidTypeForm)
     narwhals/_arrow/dataframe.py:464:20 - error: Variable not allowed in type 
expression (reportInvalidTypeForm)
     narwhals/_arrow/dataframe.py:465:38 - error: Variable not allowed in type 
expression (reportInvalidTypeForm)
   narwhals/_arrow/namespace.py
     narwhals/_arrow/namespace.py:160:17 - error: Argument of type "Overload[() 
-> _Scalar_CoT@max_element_wise, () -> Expression]" cannot be assigned to 
parameter "function" of type "(_T@reduce, _S@reduce) -> _T@reduce" in function 
"reduce"
       No overloaded function matches type "(ChunkedArrayAny, ChunkedArrayAny) 
-> ChunkedArrayAny" (reportArgumentType)
     narwhals/_arrow/namespace.py:184:29 - error: Argument of type 
"ChunkedArrayAny | _Scalar_CoT@max_element_wise" cannot be assigned to 
parameter "native_series" of type "ChunkedArrayAny" in function "__init__"
       Type "ChunkedArrayAny | Scalar[Unknown]*" is not assignable to type 
"ChunkedArrayAny"
         "Scalar[Unknown]*" is not assignable to "ChunkedArray[Any]" 
(reportArgumentType)
   narwhals/_arrow/series.py
     narwhals/_arrow/series.py:224:47 - error: Expected 0 positional arguments 
(reportCallIssue)
     narwhals/_arrow/series.py:228:51 - error: Expected 0 positional arguments 
(reportCallIssue)
     narwhals/_arrow/series.py:232:45 - error: Expected 0 positional arguments 
(reportCallIssue)
     narwhals/_arrow/series.py:236:48 - error: Expected 0 positional arguments 
(reportCallIssue)
     narwhals/_arrow/series.py:240:42 - error: Expected 0 positional arguments 
(reportCallIssue)
     narwhals/_arrow/series.py:267:46 - error: Expected 0 positional arguments 
(reportCallIssue)
     narwhals/_arrow/series.py:274:46 - error: Expected 0 positional arguments 
(reportCallIssue)
     narwhals/_arrow/series.py:306:27 - error: Expected 0 positional arguments 
(reportCallIssue)
     narwhals/_arrow/series.py:306:44 - error: Expected 0 positional arguments 
(reportCallIssue)
     narwhals/_arrow/series.py:312:27 - error: Expected 0 positional arguments 
(reportCallIssue)
     narwhals/_arrow/series.py:312:46 - error: Expected 0 positional arguments 
(reportCallIssue)
     narwhals/_arrow/series.py:355:47 - error: Expected 0 positional arguments 
(reportCallIssue)
     narwhals/_arrow/series.py:358:47 - error: Expected 0 positional arguments 
(reportCallIssue)
     narwhals/_arrow/series.py:361:50 - error: Expected 0 positional arguments 
(reportCallIssue)
     narwhals/_arrow/series.py:365:50 - error: Expected 0 positional arguments 
(reportCallIssue)
     narwhals/_arrow/series.py:403:25 - error: Expected 0 positional arguments 
(reportCallIssue)
     narwhals/_arrow/series.py:415:25 - error: Expected 0 positional arguments 
(reportCallIssue)
     narwhals/_arrow/series.py:418:25 - error: Expected 0 positional arguments 
(reportCallIssue)
     narwhals/_arrow/series.py:531:20 - error: Expected 0 positional arguments 
(reportCallIssue)
     narwhals/_arrow/series.py:545:35 - error: Expected 0 positional arguments 
(reportCallIssue)
     narwhals/_arrow/series.py:546:26 - error: Expected 0 positional arguments 
(reportCallIssue)
     narwhals/_arrow/series.py:547:33 - error: Expected 0 positional arguments 
(reportCallIssue)
     narwhals/_arrow/series.py:549:29 - error: Expected 0 positional arguments 
(reportCallIssue)
     narwhals/_arrow/series.py:550:32 - error: Expected 0 positional arguments 
(reportCallIssue)
     narwhals/_arrow/series.py:551:33 - error: Expected 0 positional arguments 
(reportCallIssue)
     narwhals/_arrow/series.py:553:29 - error: Expected 0 positional arguments 
(reportCallIssue)
     narwhals/_arrow/series.py:554:26 - error: Expected 0 positional arguments 
(reportCallIssue)
     narwhals/_arrow/series.py:555:33 - error: Expected 0 positional arguments 
(reportCallIssue)
     narwhals/_arrow/series.py:557:35 - error: Expected 0 positional arguments 
(reportCallIssue)
     narwhals/_arrow/series.py:558:32 - error: Expected 0 positional arguments 
(reportCallIssue)
     narwhals/_arrow/series.py:559:33 - error: Expected 0 positional arguments 
(reportCallIssue)
     narwhals/_arrow/series.py:568:44 - error: Expected 0 positional arguments 
(reportCallIssue)
     narwhals/_arrow/series.py:664:39 - error: Expected 0 positional arguments 
(reportCallIssue)
     narwhals/_arrow/series.py:763:46 - error: Expected 0 positional arguments 
(reportCallIssue)
     narwhals/_arrow/series.py:765:43 - error: Expected 0 positional arguments 
(reportCallIssue)
     narwhals/_arrow/series.py:795:16 - error: Variable not allowed in type 
expression (reportInvalidTypeForm)
     narwhals/_arrow/series.py:863:38 - error: No overloads for "<anonymous 
function>" match the provided arguments
       Argument types: (ChunkedArrayAny, ChunkedArrayAny | ScalarAny | None) 
(reportCallIssue)
     narwhals/_arrow/series.py:867:33 - error: No overloads for "<anonymous 
function>" match the provided arguments
       Argument types: (ChunkedArrayAny, ChunkedArrayAny | ScalarAny) 
(reportCallIssue)
     narwhals/_arrow/series.py:894:31 - error: Expected 0 positional arguments 
(reportCallIssue)
     narwhals/_arrow/series.py:896:36 - error: Expected 0 positional arguments 
(reportCallIssue)
     narwhals/_arrow/series.py:902:31 - error: Expected 0 positional arguments 
(reportCallIssue)
     narwhals/_arrow/series.py:904:36 - error: Expected 0 positional arguments 
(reportCallIssue)
     narwhals/_arrow/series.py:910:32 - error: Expected 0 positional arguments 
(reportCallIssue)
     narwhals/_arrow/series.py:912:37 - error: Expected 0 positional arguments 
(reportCallIssue)
     narwhals/_arrow/series.py:1030:20 - error: Variable not allowed in type 
expression (reportInvalidTypeForm)
     narwhals/_arrow/series.py:1161:24 - error: Expected 0 positional arguments 
(reportCallIssue)
     narwhals/_arrow/series.py:1178:34 - error: Expected 0 positional arguments 
(reportCallIssue)
     narwhals/_arrow/series.py:1178:68 - error: Expected 0 positional arguments 
(reportCallIssue)
   narwhals/_arrow/series_dt.py
     narwhals/_arrow/series_dt.py:51:9 - error: Type "dict[tuple[Literal['ns'], 
Literal['us']] | tuple[Literal['ns'], Literal['ms']] | tuple[Literal['us'], 
Literal['ns']] | tuple[Literal['us'], Literal['ms']] | tuple[Literal['ms'], 
Literal['ns']] | tuple[Literal['ms'], Literal['us']] | tuple[Literal['s'], 
Literal['ns']] | tuple[Literal['s'], Literal['us']] | tuple[Literal['s'], 
Literal['ms']], tuple[(left: ArrayOrScalar, right: ArrayOrScalar, /) -> Any, 
Literal[1000]] | tuple[(left: ArrayOrScalar, right: ArrayOrScalar, /) -> Any, 
Literal[1000000]] | tuple[() -> Unknown, Literal[1000]] | tuple[() -> Unknown, 
Literal[1000000]] | tuple[() -> Unknown, Literal[1000000000]]]" is not 
assignable to declared type "Mapping[tuple[UnitCurrent, UnitTarget], 
tuple[BinOpBroadcast, IntoRhs]]"
       Type "() -> Unknown" is not assignable to type "BinOpBroadcast"
         Function accepts too many positional parameters; expected 0 but 
received 2
       Type "() -> Unknown" is not assignable to type "BinOpBroadcast"
         Function accepts too many positional parameters; expected 0 but 
received 2
       Type "() -> Unknown" is not assignable to type "BinOpBroadcast"
         Function accepts too many positional parameters; expected 0 but 
received 2
       Type "() -> Unknown" is not assignable to type "BinOpBroadcast"
         Function accepts too many positional parameters; expected 0 but 
received 2 (reportAssignmentType)
     narwhals/_arrow/series_dt.py:105:34 - error: Expected 0 positional 
arguments (reportCallIssue)
     narwhals/_arrow/series_dt.py:107:49 - error: Expected 0 positional 
arguments (reportCallIssue)
     narwhals/_arrow/series_dt.py:115:41 - error: Expected 0 positional 
arguments (reportCallIssue)
     narwhals/_arrow/series_dt.py:118:42 - error: Expected 0 positional 
arguments (reportCallIssue)
     narwhals/_arrow/series_dt.py:127:43 - error: Expected 0 positional 
arguments (reportCallIssue)
     narwhals/_arrow/series_dt.py:130:43 - error: Expected 0 positional 
arguments (reportCallIssue)
     narwhals/_arrow/series_dt.py:133:48 - error: Expected 0 positional 
arguments (reportCallIssue)
     narwhals/_arrow/series_dt.py:137:37 - error: Expected 0 positional 
arguments (reportCallIssue)
     narwhals/_arrow/series_dt.py:137:52 - error: Expected 0 positional 
arguments (reportCallIssue)
     narwhals/_arrow/series_dt.py:137:85 - error: Expected 0 positional 
arguments (reportCallIssue)
     narwhals/_arrow/series_dt.py:142:25 - error: Expected 0 positional 
arguments (reportCallIssue)
     narwhals/_arrow/series_dt.py:142:78 - error: Expected 0 positional 
arguments (reportCallIssue)
     narwhals/_arrow/series_dt.py:147:48 - error: Expected 0 positional 
arguments (reportCallIssue)
     narwhals/_arrow/series_dt.py:181:49 - error: Expected 0 positional 
arguments (reportCallIssue)
     narwhals/_arrow/series_dt.py:193:49 - error: Expected 0 positional 
arguments (reportCallIssue)
     narwhals/_arrow/series_dt.py:204:45 - error: Expected 0 positional 
arguments (reportCallIssue)
     narwhals/_arrow/series_dt.py:209:31 - error: Expected 0 positional 
arguments (reportCallIssue)
     narwhals/_arrow/series_dt.py:223:22 - error: No overloads for 
"assume_timezone" match the provided arguments (reportCallIssue)
     narwhals/_arrow/series_dt.py:223:41 - error: Argument of type 
"TimestampArray | DurationScalar[Any]" cannot be assigned to parameter 
"timestamps" of type "Expression" in function "assume_timezone"
       Type "TimestampArray | DurationScalar[Any]" is not assignable to type 
"Expression"
         "TimestampArray" is not assignable to "Expression" (reportArgumentType)
   narwhals/_arrow/series_str.py
     narwhals/_arrow/series_str.py:24:22 - error: Expected 0 positional 
arguments (reportCallIssue)
     narwhals/_arrow/series_str.py:43:26 - error: Expected 0 positional 
arguments (reportCallIssue)
     narwhals/_arrow/series_str.py:56:44 - error: Expected 0 positional 
arguments (reportCallIssue)
     narwhals/_arrow/series_str.py:77:47 - error: Expected 0 positional 
arguments (reportCallIssue)
     narwhals/_arrow/series_str.py:80:47 - error: Expected 0 positional 
arguments (reportCallIssue)
     narwhals/_arrow/series_str.py:83:47 - error: Expected 0 positional 
arguments (reportCallIssue)
     narwhals/_arrow/series_str.py:95:35 - error: Expected 0 positional 
arguments (reportCallIssue)
     narwhals/_arrow/series_str.py:106:47 - error: Expected 0 positional 
arguments (reportCallIssue)
     narwhals/_arrow/series_str.py:116:26 - error: Expected 0 positional 
arguments (reportCallIssue)
   narwhals/_arrow/utils.py
     narwhals/_arrow/utils.py:278:30 - error: Expected 0 positional arguments 
(reportCallIssue)
     narwhals/_arrow/utils.py:284:42 - error: Expected 0 positional arguments 
(reportCallIssue)
     narwhals/_arrow/utils.py:291:42 - error: Expected 0 positional arguments 
(reportCallIssue)
     narwhals/_arrow/utils.py:291:54 - error: Expected 0 positional arguments 
(reportCallIssue)
     narwhals/_arrow/utils.py:293:17 - error: Expected 0 positional arguments 
(reportCallIssue)
     narwhals/_arrow/utils.py:293:33 - error: Expected 0 positional arguments 
(reportCallIssue)
     narwhals/_arrow/utils.py:297:29 - error: Expected 0 positional arguments 
(reportCallIssue)
     narwhals/_arrow/utils.py:305:27 - error: Expected 0 positional arguments 
(reportCallIssue)
     narwhals/_arrow/utils.py:387:43 - error: Variable not allowed in type 
expression (reportInvalidTypeForm)
     narwhals/_arrow/utils.py:388:43 - error: Variable not allowed in type 
expression (reportInvalidTypeForm)
     narwhals/_arrow/utils.py:396:29 - error: Variable not allowed in type 
expression (reportInvalidTypeForm)
     narwhals/_arrow/utils.py:416:29 - error: Variable not allowed in type 
expression (reportInvalidTypeForm)
   narwhals/_pandas_like/series_dt.py
     narwhals/_pandas_like/series_dt.py:81:29 - error: Expected 0 positional 
arguments (reportCallIssue)
     narwhals/_pandas_like/series_dt.py:81:44 - error: Expected 0 positional 
arguments (reportCallIssue)
     narwhals/_pandas_like/series_dt.py:81:78 - error: Expected 0 positional 
arguments (reportCallIssue)
     narwhals/_pandas_like/series_dt.py:227:48 - error: Expected 0 positional 
arguments (reportCallIssue)
   narwhals/_plan/arrow/expr.py
     narwhals/_plan/arrow/expr.py:137:37 - error: Argument of type "() -> 
Unknown" cannot be assigned to parameter "fn_native" of type "(Any) -> Any" in 
function "_unary_function"
       Type "() -> Unknown" is not assignable to type "(Any) -> Any"
         Function accepts too many positional parameters; expected 0 but 
received 1 (reportArgumentType)
     narwhals/_plan/arrow/expr.py:264:43 - error: Expected 0 positional 
arguments (reportCallIssue)
     narwhals/_plan/arrow/expr.py:269:57 - error: Expected 0 positional 
arguments (reportCallIssue)
     narwhals/_plan/arrow/expr.py:309:40 - error: Expected 0 positional 
arguments (reportCallIssue)
     narwhals/_plan/arrow/expr.py:321:40 - error: Expected 0 positional 
arguments (reportCallIssue)
   narwhals/_plan/arrow/functions.py
     narwhals/_plan/arrow/functions.py:91:16 - error: Expected 0 positional 
arguments (reportCallIssue)
     narwhals/_plan/arrow/functions.py:91:30 - error: Expected 0 positional 
arguments (reportCallIssue)
     narwhals/_plan/arrow/functions.py:184:19 - error: Expected 0 positional 
arguments (reportCallIssue)
   narwhals/_plan/arrow/namespace.py
     narwhals/_plan/arrow/namespace.py:123:42 - error: Argument of type 
"Overload[() -> _Scalar_CoT@max_element_wise, () -> Expression]" cannot be 
assigned to parameter "fn_native" of type "(Any, Any) -> Any" in function 
"_horizontal_function"        
       No overloaded function matches type "(Any, Any) -> Any" 
(reportArgumentType)
   narwhals/_plan/arrow/typing.py
     narwhals/_plan/arrow/typing.py:52:39 - error: Variable not allowed in type 
expression (reportInvalidTypeForm)
   narwhals/_polars/dataframe.py
     narwhals/_polars/dataframe.py:474:34 - error: No overloads for 
"__getitem__" match the provided arguments (reportCallIssue)
     narwhals/_polars/dataframe.py:474:34 - error: Argument of type 
"tuple[slice[None, None, None], int | Sequence[int] | Series[Any] | 
CompliantSeries[Any] | ndarray[tuple[int], dtype[integer[Any]]]]" cannot be 
assigned to parameter "key" of type "MultiIndexSelector | MultiColSelector | 
SingleIndexSelector | tuple[SingleIndexSelector, MultiColSelector] | 
tuple[MultiIndexSelector, MultiColSelector]" in function "__getitem__"
       Type "tuple[slice[None, None, None], int | Sequence[int] | Series[Any] | 
CompliantSeries[Any] | ndarray[tuple[int], dtype[integer[Any]]]]" is not 
assignable to type "MultiIndexSelector | MultiColSelector | SingleIndexSelector 
| tuple[SingleIndexSelector, MultiColSelector] | tuple[MultiIndexSelector, 
MultiColSelector]"
         "tuple[slice[None, None, None], int | Sequence[int] | Series[Any] | 
CompliantSeries[Any] | ndarray[tuple[int], dtype[integer[Any]]]]" is not 
assignable to "int"
         "tuple[slice[None, None, None], int | Sequence[int] | Series[Any] | 
CompliantSeries[Any] | ndarray[tuple[int], dtype[integer[Any]]]]" is not 
assignable to "slice[Any, Any, Any]"
         "tuple[slice[None, None, None], int | Sequence[int] | Series[Any] | 
CompliantSeries[Any] | ndarray[tuple[int], dtype[integer[Any]]]]" is not 
assignable to "range"
         "tuple[slice[None, None, None], int | Sequence[int] | Series[Any] | 
CompliantSeries[Any] | ndarray[tuple[int], dtype[integer[Any]]]]" is not 
assignable to "Sequence[int]"
           Type parameter "_T_co@Sequence" is covariant, but "slice[None, None, 
None] | int | Sequence[int] | Series[Any] | CompliantSeries[Any] | 
ndarray[tuple[int], dtype[integer[Any]]]" is not a subtype of "int"
             Type "slice[None, None, None] | int | Sequence[int] | Series[Any] 
| CompliantSeries[Any] | ndarray[tuple[int], dtype[integer[Any]]]" is not 
assignable to type "int"
               "CompliantSeries[Any]" is not assignable to "int" 
(reportArgumentType)
   narwhals/_utils.py
     narwhals/_utils.py:1034:18 - error: No overloads for "__new__" match the 
provided arguments (reportCallIssue)
   narwhals/functions.py
     narwhals/functions.py:579:40 - error: Cannot access attribute "name" for 
class "Distribution"
       Attribute "name" is unknown (reportAttributeAccessIssue)
   113 errors, 0 warnings, 0 informations
   ```
   
   </p>
   </details> 
   
   The fixes are usually pretty simple and specified here 
   - 
https://typing.python.org/en/latest/spec/directives.html#version-and-platform-checking



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to