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

best approach to allow @/matmult? #268

Closed
rawwerks opened this issue Feb 1, 2024 · 3 comments · Fixed by #270
Closed

best approach to allow @/matmult? #268

rawwerks opened this issue Feb 1, 2024 · 3 comments · Fixed by #270

Comments

@rawwerks
Copy link

rawwerks commented Feb 1, 2024

hi! i'm sorry if this isn't the right place to ask this question, but i couldn't find anywhere else that the cool RestrictedPython people hang out.

i'm using a python package that is basically a domain-specific language, and one of the features of the language is overwriting @ to have a specific definition.

after failing repeatedly to do a workaround where i overwrite @ with AST before getting the safe code, i think i need to find a way to allow ___matmult___ (or more accurately, allow the @ to be in the code)

what would be the recommended way to do this?

the simplest way i can think of is to fork the repo & change this line to allow the node to be visited.

def visit_MatMult(self, node):

for both safety and maintainability, i would prefer to avoid changing the source code if possible.

is there a more elegant way to tell restrictedpython that it needs to allow @ ? can i add a @ function to the safe_globals that just passes the symbol through?

to clarify once again - i don't need ___matmult___, i need restrictedpython to allow the @ so i can use the package-specific definition of the @ symbol.

@icemac
Copy link
Member

icemac commented Feb 1, 2024

@rawwerks You could create a PR where visit_MatMult calls return self.node_contents_visit(node) like the other binary operators.
It is currently not allowed, because there was no use-case, yet, and we were not able to come up with example code for the tests: There seems to be no usage in plain Python.

@rawwerks
Copy link
Author

rawwerks commented Feb 9, 2024

thank you @icemac !

i finally found the 20 seconds required to make this PR.

@icemac
Copy link
Member

icemac commented Mar 14, 2024

Released in https://pypi.org/project/RestrictedPython/7.1/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants