@@ -363,7 +363,7 @@ class CachedExpressionConvertible(Protocol):
363
363
364
364
_oqpy_cache_key : Hashable
365
365
366
- def _to_cached_oqpy_expression (self ) -> HasToAst : ... # pragma: no cover
366
+ def _to_cached_oqpy_expression (self ) -> AstConvertible : ... # pragma: no cover
367
367
368
368
369
369
class OQPyUnaryExpression (OQPyExpression ):
@@ -490,8 +490,10 @@ def to_ast(program: Program, item: AstConvertible) -> ast.Expression:
490
490
if item ._oqpy_cache_key is None :
491
491
item ._oqpy_cache_key = uuid .uuid1 ()
492
492
if item ._oqpy_cache_key not in program .expr_cache :
493
- program .expr_cache [item ._oqpy_cache_key ] = item ._to_cached_oqpy_expression ()
494
- item = program .expr_cache [item ._oqpy_cache_key ]
493
+ program .expr_cache [item ._oqpy_cache_key ] = to_ast (
494
+ program , item ._to_cached_oqpy_expression ()
495
+ )
496
+ return program .expr_cache [item ._oqpy_cache_key ]
495
497
if isinstance (item , (complex , np .complexfloating )):
496
498
if item .imag == 0 :
497
499
return to_ast (program , item .real )
@@ -507,7 +509,9 @@ def to_ast(program: Program, item: AstConvertible) -> ast.Expression:
507
509
ast .ImaginaryLiteral (- item .imag ),
508
510
)
509
511
return ast .BinaryExpression (
510
- ast .BinaryOperator ["+" ], ast .FloatLiteral (item .real ), ast .ImaginaryLiteral (item .imag )
512
+ ast .BinaryOperator ["+" ],
513
+ ast .FloatLiteral (item .real ),
514
+ ast .ImaginaryLiteral (item .imag ),
511
515
)
512
516
if isinstance (item , (bool , np .bool_ )):
513
517
return ast .BooleanLiteral (item )
0 commit comments