Skip to content

[triton] Python typing improvements#10048

Merged
Mogball merged 3 commits into
mainfrom
jeffniu/typing
Apr 16, 2026
Merged

[triton] Python typing improvements#10048
Mogball merged 3 commits into
mainfrom
jeffniu/typing

Conversation

@Mogball
Copy link
Copy Markdown
Collaborator

@Mogball Mogball commented Apr 15, 2026

No description provided.

@Mogball Mogball requested a review from Jokeren April 15, 2026 23:57
@Jokeren
Copy link
Copy Markdown
Contributor

Jokeren commented Apr 16, 2026

Thanks. To confirm it hasn't fixed constexpr problems like the following, right?

    block_layout: ttgl.constexpr = ttgl.BlockedLayout([1, 4], [1, 32], [4, 1], [1, 0])

Incompatible types in assignment (expression has type "BlockedLayout", variable has type "constexpr")Mypyassignment

Comment thread python/triton/runtime/jit.py Outdated
@Mogball
Copy link
Copy Markdown
Collaborator Author

Mogball commented Apr 16, 2026

Thanks. To confirm it hasn't fixed constexpr problems like the following, right?

    block_layout: ttgl.constexpr = ttgl.BlockedLayout([1, 4], [1, 32], [4, 1], [1, 0])

Incompatible types in assignment (expression has type "BlockedLayout", variable has type "constexpr")Mypyassignment

No, I haven't gotten to that yet.

@Mogball Mogball merged commit f62f95b into main Apr 16, 2026
21 of 27 checks passed
@Mogball Mogball deleted the jeffniu/typing branch April 16, 2026 22:09
raymondtay pushed a commit to raymondtay/triton that referenced this pull request Apr 18, 2026
bingyizh233 pushed a commit to bingyizh233/triton that referenced this pull request Apr 20, 2026
@saagarjha
Copy link
Copy Markdown
Contributor

We also have

diff --git a/python/triton/runtime/jit.py b/python/triton/runtime/jit.py
index eaaffdfbd..0a5460e01 100644
--- a/python/triton/runtime/jit.py
+++ b/python/triton/runtime/jit.py
@@ -10,7 +10,7 @@ import textwrap
 from collections import defaultdict
 from dataclasses import dataclass
 from functools import cached_property
-from typing import Callable, Generic, Iterable, Optional, ParamSpec, TypeVar, overload, Dict, Any, Tuple
+from typing import Callable, Concatenate, Generic, Iterable, Optional, ParamSpec, TYPE_CHECKING, TypeVar, overload, Dict, Any, Tuple

 from triton.backends import BaseBackend
 from types import ModuleType
@@ -29,6 +29,7 @@ INDENT_PATTERN = re.compile(r"^(?P<indent>[ \t]*)def\s+\w+\s*\(", re.MULTILINE)
 T = TypeVar("T")
 P = ParamSpec("P")
 R = TypeVar("R")
+U = TypeVar("U")

 # -----------------------------------------------------------------------------
 # Dependencies Finder
@@ -907,6 +908,20 @@ class JITFunction(JITCallable, KernelInterface[T]):
     def __call__(self: "JITFunction[Callable[P, R]]", *args: P.args, **kwargs: P.kwargs) -> R:
         raise RuntimeError("Cannot call @triton.jit'd outside of the scope of a kernel")

+    if TYPE_CHECKING:
+
+        @overload
+        def __get__(self: "JITFunction[Callable[Concatenate[U, P], R]]", instance: U,
+                    owner: Optional[type] = None) -> Callable[P, R]:
+            ...
+
+        @overload
+        def __get__(self, instance: None, owner: Optional[type] = None) -> "JITFunction[T]":
+            ...
+
+        def __get__(self, instance, owner=None):
+            ...
+
     def __repr__(self):
         return f"JITFunction({self.module}:{self.fn.__qualname__})"

to fix member functions on aggregates

@jeffniu-openai
Copy link
Copy Markdown
Collaborator

jeffniu-openai commented Apr 22, 2026

PR plz

@leijurv leijurv mentioned this pull request Apr 23, 2026
5 tasks
leijurv added a commit to leijurv/triton that referenced this pull request Apr 23, 2026
Co-authored-by: Saagar Jha <saagar@saagarjha.com>
leijurv added a commit to leijurv/triton that referenced this pull request Apr 23, 2026
Co-authored-by: Saagar Jha <saagar@saagarjha.com>
Co-authored-by: Claude <noreply@anthropic.com>
peterbell10 pushed a commit that referenced this pull request Apr 29, 2026
@jeffniu-openai said `PR plz` here:
#10048 (comment)

Co-authored-by: Saagar Jha <saagar@saagarjha.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants