Copilot commented on code in PR #30: URL: https://github.com/apache/tvm-ffi/pull/30#discussion_r2361926919
########## python/tvm_ffi/_core_base.py: ########## @@ -0,0 +1,74 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +"""Runtime type metadata for TVM FFI bindings.""" + +from __future__ import annotations + +import dataclasses +from typing import Any, ClassVar + + [email protected](eq=False) +class TypeField: + """Description of a single reflected field on an FFI-backed type.""" + + name: str + doc: str Review Comment: The `doc` field should be Optional[str] since line 306 in object.pxi shows it can be None when `field.doc.size == 0`. ########## python/tvm_ffi/_core_base.py: ########## @@ -0,0 +1,74 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +"""Runtime type metadata for TVM FFI bindings.""" + +from __future__ import annotations + +import dataclasses +from typing import Any, ClassVar + + [email protected](eq=False) +class TypeField: + """Description of a single reflected field on an FFI-backed type.""" + + name: str + doc: str + size: int + offset: int + frozen: bool + getter: Any + setter: Any + + def as_property(self, cls: type) -> property: + """Create a Python ``property`` object for this field on ``cls``.""" + name = self.name + fget = self.getter + fset = self.setter + fget.__name__ = fset.__name__ = name + fget.__module__ = fset.__module__ = cls.__module__ + fget.__qualname__ = fset.__qualname__ = f"{cls.__qualname__}.{name}" # type: ignore[attr-defined] + fget.__doc__ = fset.__doc__ = f"Property `{name}` of class `{cls.__qualname__}`" # type: ignore[attr-defined] + + return property( + fget=fget if self.getter else None, + fset=fset if (not self.frozen) and self.setter else None, Review Comment: The condition should check `self.getter` is not None rather than truthy, since the getter could be a valid callable that evaluates to False. ```suggestion fget=fget if self.getter is not None else None, fset=fset if (not self.frozen) and self.setter is not None else None, ``` ########## python/tvm_ffi/_core_base.py: ########## @@ -0,0 +1,74 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +"""Runtime type metadata for TVM FFI bindings.""" + +from __future__ import annotations + +import dataclasses +from typing import Any, ClassVar + + [email protected](eq=False) +class TypeField: + """Description of a single reflected field on an FFI-backed type.""" + + name: str + doc: str + size: int + offset: int + frozen: bool + getter: Any + setter: Any + + def as_property(self, cls: type) -> property: + """Create a Python ``property`` object for this field on ``cls``.""" + name = self.name + fget = self.getter + fset = self.setter + fget.__name__ = fset.__name__ = name + fget.__module__ = fset.__module__ = cls.__module__ + fget.__qualname__ = fset.__qualname__ = f"{cls.__qualname__}.{name}" # type: ignore[attr-defined] + fget.__doc__ = fset.__doc__ = f"Property `{name}` of class `{cls.__qualname__}`" # type: ignore[attr-defined] Review Comment: Attempting to set attributes on `fset` when it could be None. The setter assignment should be conditional on `self.setter` being not None. ```suggestion fget.__name__ = name fget.__module__ = cls.__module__ fget.__qualname__ = f"{cls.__qualname__}.{name}" # type: ignore[attr-defined] fget.__doc__ = f"Property `{name}` of class `{cls.__qualname__}`" # type: ignore[attr-defined] if fset is not None: fset.__name__ = name fset.__module__ = cls.__module__ fset.__qualname__ = f"{cls.__qualname__}.{name}" # type: ignore[attr-defined] fset.__doc__ = f"Property `{name}` of class `{cls.__qualname__}`" # type: ignore[attr-defined] ``` ########## python/tvm_ffi/_core_base.py: ########## @@ -0,0 +1,74 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +"""Runtime type metadata for TVM FFI bindings.""" + +from __future__ import annotations + +import dataclasses +from typing import Any, ClassVar + + [email protected](eq=False) +class TypeField: + """Description of a single reflected field on an FFI-backed type.""" + + name: str + doc: str + size: int + offset: int + frozen: bool + getter: Any + setter: Any + + def as_property(self, cls: type) -> property: + """Create a Python ``property`` object for this field on ``cls``.""" + name = self.name + fget = self.getter + fset = self.setter + fget.__name__ = fset.__name__ = name + fget.__module__ = fset.__module__ = cls.__module__ + fget.__qualname__ = fset.__qualname__ = f"{cls.__qualname__}.{name}" # type: ignore[attr-defined] + fget.__doc__ = fset.__doc__ = f"Property `{name}` of class `{cls.__qualname__}`" # type: ignore[attr-defined] + + return property( + fget=fget if self.getter else None, + fset=fset if (not self.frozen) and self.setter else None, + doc=f"{cls.__module__}.{cls.__qualname__}.{name}", + ) + + [email protected](eq=False) +class TypeMethod: + """Description of a single reflected method on an FFI-backed type.""" + + name: str + doc: str Review Comment: The `doc` field should be Optional[str] since line 320 in object.pxi shows it can be None when `method.doc.size == 0`. -- 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]
