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

Operations done to variable trigger exceptions #78

Open
squidrice21 opened this issue Aug 30, 2024 · 1 comment
Open

Operations done to variable trigger exceptions #78

squidrice21 opened this issue Aug 30, 2024 · 1 comment

Comments

@squidrice21
Copy link

squidrice21 commented Aug 30, 2024

I'm running version 0.2.1. It seems that paramit can't ignore operations done to an input variable. E.g., run this:

import os

a = 'precomputed.npy'
b = 20

if not os.path.exists(a):
    a = f'precomputed_{b}' + '.npy'

triggers this:

Traceback (most recent call last):
  File "/home/envs/testenv/bin/paramit", line 8, in <module>
    sys.exit(main())
  File "/home/envs/testenv/lib/python3.9/site-packages/paramit/cli/__init__.py", line 695, in main
    modified_tree = set_global_variables_from_config(
  File "/home/envs/testenv/lib/python3.9/site-packages/paramit/cli/__init__.py", line 289, in set_global_variables_from_config
    modified_tree = wrapper.visit(transformer)
  File "/home/envs/testenv/lib/python3.9/site-packages/libcst/metadata/wrapper.py", line 204, in visit
    return self.module.visit(visitor)
  File "/home/envs/testenv/lib/python3.9/site-packages/libcst/_nodes/module.py", line 89, in visit
    result = super(Module, self).visit(visitor)
  File "/home/envs/testenv/lib/python3.9/site-packages/libcst/_nodes/base.py", line 227, in visit
    _CSTNodeSelfT, self._visit_and_replace_children(visitor)
  File "/home/envs/testenv/lib/python3.9/site-packages/libcst/_nodes/module.py", line 74, in _visit_and_replace_children
    body=visit_body_sequence(self, "body", self.body, visitor),
  File "/home/envs/testenv/lib/python3.9/site-packages/libcst/_nodes/internal.py", line 227, in visit_body_sequence
    return tuple(visit_body_iterable(parent, fieldname, children, visitor))
  File "/home/envs/testenv/lib/python3.9/site-packages/libcst/_nodes/internal.py", line 193, in visit_body_iterable
    new_child = child.visit(visitor)
  File "/home/envs/testenv/lib/python3.9/site-packages/libcst/_nodes/base.py", line 227, in visit
    _CSTNodeSelfT, self._visit_and_replace_children(visitor)
  File "/home/envs/testenv/lib/python3.9/site-packages/libcst/_nodes/statement.py", line 616, in _visit_and_replace_children
    body=visit_required(self, "body", self.body, visitor),
  File "/home/envs/testenv/lib/python3.9/site-packages/libcst/_nodes/internal.py", line 81, in visit_required
    result = node.visit(visitor)
  File "/home/envs/testenv/lib/python3.9/site-packages/libcst/_nodes/base.py", line 227, in visit
    _CSTNodeSelfT, self._visit_and_replace_children(visitor)
  File "/home/envs/testenv/lib/python3.9/site-packages/libcst/_nodes/statement.py", line 698, in _visit_and_replace_children
    body=visit_body_sequence(self, "body", self.body, visitor),
  File "/home/envs/testenv/lib/python3.9/site-packages/libcst/_nodes/internal.py", line 227, in visit_body_sequence
    return tuple(visit_body_iterable(parent, fieldname, children, visitor))
  File "/home/envs/testenv/lib/python3.9/site-packages/libcst/_nodes/internal.py", line 193, in visit_body_iterable
    new_child = child.visit(visitor)
  File "/home/envs/testenv/lib/python3.9/site-packages/libcst/_nodes/base.py", line 227, in visit
    _CSTNodeSelfT, self._visit_and_replace_children(visitor)
  File "/home/envs/testenv/lib/python3.9/site-packages/libcst/_nodes/statement.py", line 443, in _visit_and_replace_children
    body=visit_sequence(self, "body", self.body, visitor),
  File "/home/envs/testenv/lib/python3.9/site-packages/libcst/_nodes/internal.py", line 177, in visit_sequence
    return tuple(visit_iterable(parent, fieldname, children, visitor))
  File "/home/envs/testenv/lib/python3.9/site-packages/libcst/_nodes/internal.py", line 159, in visit_iterable
    new_child = child.visit(visitor)
  File "/home/envs/testenv/lib/python3.9/site-packages/libcst/_nodes/base.py", line 236, in visit
    leave_result = visitor.on_leave(self, with_updated_children)
  File "/home/envs/testenv/lib/python3.9/site-packages/libcst/_visitors.py", line 71, in on_leave
    updated_node = leave_func(original_node, updated_node)
  File "/home/envs/testenv/lib/python3.9/site-packages/paramit/cli/__init__.py", line 197, in leave_Assign
    raise ValueError(
ValueError: Unsupported type <class 'str'>, <class 'libcst._nodes.expression.BinaryOperation'>
@squidrice21
Copy link
Author

Similarly, local and global variables can also cause problems:

a = 10
c = 40


def a2c(a):
    c = a / 2
    return c

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

No branches or pull requests

1 participant