junrushao commented on code in PR #35:
URL: https://github.com/apache/tvm-ffi/pull/35#discussion_r2366472104
##########
examples/quick_start/run_example.py:
##########
@@ -16,15 +16,9 @@
# under the License.
"""Quick start script to run tvm-ffi examples from prebuilt libraries."""
-import tvm_ffi
-
-try:
- import torch
-except ImportError:
- torch = None
Review Comment:
We may simply assume `torch` exists under `examples`
##########
python/tvm_ffi/cpp/load_inline.py:
##########
@@ -358,17 +358,17 @@ def _decorate_with_tvm_ffi(source: str, functions:
Mapping[str, str]) -> str:
return "\n".join(sources)
-def load_inline(
+def load_inline( # noqa: PLR0912, PLR0915
name: str,
*,
- cpp_sources: str | None = None,
- cuda_sources: str | None = None,
- functions: Sequence[str] | None = None,
+ cpp_sources: Sequence[str] | str | None = None,
+ cuda_sources: Sequence[str] | str | None = None,
+ functions: Mapping[str, str] | Sequence[str] | str | None = None,
Review Comment:
seems that mypy catches a type error here
##########
python/tvm_ffi/testing.py:
##########
@@ -16,23 +16,37 @@
# under the License.
"""Testing utilities."""
-from typing import Any, ClassVar
+from typing import TYPE_CHECKING, Any, ClassVar
from . import _ffi_api
from .core import Object
from .dataclasses import c_class, field
from .registry import register_object
+if TYPE_CHECKING:
+ from tvm_ffi import Array, Map
+
@register_object("testing.TestObjectBase")
class TestObjectBase(Object):
"""Test object base class."""
+ if TYPE_CHECKING:
+ v_i64: int
+ v_f64: float
+ v_str: str
+
+ def add_i64(self, x: int) -> int: ... # noqa: D102
Review Comment:
ditto
##########
python/tvm_ffi/_ffi_api.py:
##########
@@ -16,6 +16,37 @@
# under the License.
"""FFI API."""
+from __future__ import annotations
+
+from typing import TYPE_CHECKING, Any
+
from . import registry
+if TYPE_CHECKING:
Review Comment:
Alternatively, we may:
- Option A) Suppress type errors on all `_ffi_api.*` access
- Option B) Auto generate stubs in another `*.pyi` file
##########
python/tvm_ffi/access_path.py:
##########
@@ -39,11 +39,30 @@ class AccessKind(IntEnum):
class AccessStep(core.Object):
"""Access step container."""
+ if TYPE_CHECKING:
+ kind: AccessKind
+ key: Any
+
@register_object("ffi.reflection.AccessPath")
class AccessPath(core.Object):
"""Access path container."""
+ if TYPE_CHECKING:
Review Comment:
ditto. We may want either a separate stub file via stub generation, or
suppress type errors
##########
python/tvm_ffi/testing.py:
##########
@@ -90,5 +108,5 @@ class _TestCxxClassDerived(_TestCxxClassBase):
@c_class("testing.TestCxxClassDerivedDerived")
class _TestCxxClassDerivedDerived(_TestCxxClassDerived):
- v_str: str = field(default_factory=lambda: "default")
- v_bool: bool
+ v_str: str = field(default_factory=lambda: "default") # type:
ignore[assignment]
Review Comment:
TODO: need to figure out why `field(...)` triggers a mypy complain, despite
`field_specifiers` are used properly
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]