Skip to content

Commit

Permalink
Allow isinstance calls without first-parameter names
Browse files Browse the repository at this point in the history
Now prints a warning using the new proper warning logger
  • Loading branch information
nielstron committed Mar 16, 2024
1 parent 1686f00 commit 9bd6afb
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions opshin/type_inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,11 @@ def visit_Call(self, node: Call) -> TypeMapPair:
if not (isinstance(node.func, Name) and node.func.orig_id == "isinstance"):
return ({}, {})
# special case for Union
assert isinstance(
node.args[0], Name
), "Target 0 of an isinstance cast must be a variable name"
if not isinstance(node.args[0], Name):
OPSHIN_LOGGER.warning(
"Target 0 of an isinstance cast must be a variable name for type casting to work. You can still proceed, but the inferred type of the isinstance cast will not be accurate."
)
return ({}, {})
assert isinstance(
node.args[1], Name
), "Target 1 of an isinstance cast must be a class name"
Expand Down

0 comments on commit 9bd6afb

Please sign in to comment.