Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Transform] Use callable() instead of isinstance() for type checking #14248

Merged
merged 1 commit into from
Mar 11, 2023

Conversation

Lunderberg
Copy link
Contributor

Previously, type-checking of a callable arguments, such as to tvm.ir.transform.module_pass, was done using isinstance(arg, (types.FunctionType, types.LambdaType)). This check can give false negatives for valid python types, such as a bound method or an instance of a class that implements __call__.

This commit replaces the checks with the builtin function callable(), which handles any Python object that can be called using function-like syntax.

Previously, type-checking of a callable arguments, such as to
`tvm.ir.transform.module_pass`, was done using
`isinstance(arg, (types.FunctionType, types.LambdaType))`.  This check
can give false negatives for valid python types, such as a bound
method or an instance of a class that implements `__call__`.

This commit replaces the checks with the builtin function `callable()`,
which handles any Python object that can be called using function-like
syntax.
@tvm-bot
Copy link
Collaborator

tvm-bot commented Mar 9, 2023

Thanks for contributing to TVM! Please refer to the contributing guidelines https://tvm.apache.org/docs/contribute/ for useful information and tips. Please request code reviews from Reviewers by @-ing them in a comment.

  • No users to tag found in teams: transform See #10317 for details

Generated by tvm-bot

@tqchen tqchen merged commit 92de8e9 into apache:main Mar 11, 2023
@Lunderberg Lunderberg deleted the builtin_callable branch March 12, 2023 02:12
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.

3 participants