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

old nodes import the parser module (deprecated) #4505

Closed
zeffii opened this issue Jun 2, 2022 · 4 comments
Closed

old nodes import the parser module (deprecated) #4505

zeffii opened this issue Jun 2, 2022 · 4 comments

Comments

@zeffii
Copy link
Collaborator

zeffii commented Jun 2, 2022

what to do.. replace with ast.parse() ?

@Durman
Copy link
Collaborator

Durman commented Jun 3, 2022

If we'd know for sure that it does not change its behavior it's worth to replace.
If it does change, it can break layouts and users wont be able to understand the cause of it.

In the last case probably it would be better to remove the node implementation and show the message that, for example, Sverchok 1.0 was the last version where the node was supported. And we can wait till the deprecated module will be removed before doing this.

@zeffii
Copy link
Collaborator Author

zeffii commented Jun 3, 2022

in py3.10 parser is gone from standard libs. It is not a big deal, the nodes don't use the module extensively..

in essence they use these features:

string_formula = 'x*n[0]'
x = 10
n = [20, 30]

we use

import parser
code_formula = parser.expr(string_formula).compile()
k = eval(code_formula)

print(k)
# >>> 200

equivalent is

# without parser module
code_formula = compile(string_formula, '<string>', mode='eval')
k = eval(code_formula)

print(k)
# >>> 200

the main difference would be slightly different error messages, but failure to parse would still be failure to parse.

@zeffii
Copy link
Collaborator Author

zeffii commented Jun 3, 2022

a replacement could be

try:
    import parser
except:
    from dataclasses import dataclass

    @dataclass
    class Expr(str):
        str_formula: str
        def compile(self):
            # print('use mock')
            return compile(self.str_formula, '<string>', mode='eval')

    parser = lambda: None
    parser.expr = lambda str_formula: Expr(str_formula)

@zeffii
Copy link
Collaborator Author

zeffii commented Jun 3, 2022

resolved: #4509

@zeffii zeffii closed this as completed Jun 3, 2022
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

2 participants