Ubospica commented on code in PR #608: URL: https://github.com/apache/tvm-ffi/pull/608#discussion_r3397881144
########## python/tvm_ffi/stub/python_generator/utils.py: ########## @@ -0,0 +1,303 @@ +# 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. +"""Python generator helpers for ``tvm-ffi-stubgen``. + +This module groups two Python-specific concerns: + +- import modelling (:class:`ImportItem`, :class:`PythonImports`) +- stub rendering helpers for function/object signatures +""" + +from __future__ import annotations + +import dataclasses +from io import StringIO +from typing import Callable + +from ..utils import FuncInfo, ObjectInfo +from . import consts as C + + [email protected](frozen=True, eq=True) +class ImportItem: + """An import statement item.""" + + mod: str + name: str + type_checking_only: bool = False + alias: str | None = None + + def __init__( + self, + full_name: str, + type_checking_only: bool = False, + alias: str | None = None, + ) -> None: + """Initialize an `ImportItem` from a dotted ``module.symbol`` name and optional alias.""" + if "." in full_name: + mod, name = full_name.rsplit(".", 1) + for mod_prefix, mod_replacement in C.MOD_MAP.items(): + if mod == mod_prefix or mod.startswith(mod_prefix + "."): Review Comment: We can add a regression here -- 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]
