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

getattr(Array, 'from') raises AttributeError #3921

Closed
MarcSkovMadsen opened this issue Jun 11, 2023 · 4 comments · Fixed by #3926
Closed

getattr(Array, 'from') raises AttributeError #3921

MarcSkovMadsen opened this issue Jun 11, 2023 · 4 comments · Fixed by #3926
Labels
bug Something isn't working documentation

Comments

@MarcSkovMadsen
Copy link

MarcSkovMadsen commented Jun 11, 2023

🐛 Bug

The example in How can I access JavaScript objects/attributes in Python if their names are Python keywords? raises AttributeError: from

To Reproduce

<!doctype html>
<html>
  <head>
      <script src="https://cdn.jsdelivr.net/pyodide/v0.23.2/full/pyodide.js"></script>
  </head>
  <body>
    Pyodide test page <br>
    Open your browser console to see Pyodide output
    <script type="text/javascript">
      async function main(){
        let pyodide = await loadPyodide();
        console.log(pyodide.runPython(`
            import sys
            sys.version
        `));
        pyodide.runPython(`
from js import Array
fromFunc = getattr(Array, 'from')
print(fromFunc([1,2,3]))
		`);
      }
      main();
    </script>
  </body>
</html>

image

Expected behavior

No exception raised and I can use the fromFunc.

Environment

  • Pyodide Version: 0.23.2
  • Browser version: Edge Version 114.0.1823.41 (Official build) (64-bit)

Additional context

I'm trying to use PIXI.js and would like to be able to use its PIXI.Sprite.from method.

Workaround

Downgrade to 0.21.2 (random choice). Then it works

image

0.22.1 is the latest version of Pyodide I can get this working with.

@MarcSkovMadsen MarcSkovMadsen added the bug Something isn't working label Jun 11, 2023
@ryanking13
Copy link
Member

Thanks for the report @MarcSkovMadsen.

We changed how we handle reserved keywords in #3617, so you need to append the underscore now:

from js import Array

Array.from_
getattr(Array, "from_")

We need to update the document.

@hoodmane
Copy link
Member

Huh I wonder why we don't make getattr(Array, "from") work too...

@ryanking13
Copy link
Member

ryanking13 commented Jun 12, 2023

Huh I wonder why we don't make getattr(Array, "from") work too...

Indeed, it is interesting that it is a regression.

@hoodmane
Copy link
Member

We should probably release an 0.23.3 with a fix for this.

hoodmane added a commit to hoodmane/pyodide that referenced this issue Jun 12, 2023
hoodmane added a commit to hoodmane/pyodide that referenced this issue Jun 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working documentation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants