Skip to content

Commit f6d0478

Browse files
timsaucerclaude
andcommitted
fix: resolve the _PyCapsule type alias so capsule overloads type-check
user_defined.py imported CapsuleType from _typeshed, which does not define it. Pyright reports `"CapsuleType" is unknown import symbol`, so _PyCapsule resolved to Unknown and every overload and parameter typed with it accepted any argument. This affected the udaf/from_pycapsule hints added in #1277 as well as the new udf/udwf ones. Import it from types on Python 3.13+ and from typing_extensions (already a dependency below 3.13) otherwise. Checked with pyright at --pythonversion 3.10 and 3.13: udf/udaf/udwf and each from_pycapsule accept a CapsuleType and return the right wrapper, and WindowUDF.from_pycapsule(1) is now rejected where it previously passed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 5d43576 commit f6d0478

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

‎python/datafusion/user_defined.py‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,12 @@
3131
from datafusion.expr import Expr
3232

3333
if TYPE_CHECKING:
34-
from _typeshed import CapsuleType as _PyCapsule
34+
import sys
35+
36+
if sys.version_info >= (3, 13):
37+
from types import CapsuleType as _PyCapsule
38+
else:
39+
from typing_extensions import CapsuleType as _PyCapsule
3540

3641
_R = TypeVar("_R", bound=pa.Array)
3742
from collections.abc import Callable, Sequence

0 commit comments

Comments
 (0)