From 9bd6afb78bc932a9256eeb6e0c2881a7cca87012 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niels=20M=C3=BCndler?= Date: Sun, 17 Mar 2024 00:09:05 +0100 Subject: [PATCH] Allow isinstance calls without first-parameter names Now prints a warning using the new proper warning logger --- opshin/type_inference.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/opshin/type_inference.py b/opshin/type_inference.py index 00db62ed..f9b0939b 100644 --- a/opshin/type_inference.py +++ b/opshin/type_inference.py @@ -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"