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

Please help with defaultdict implementation #778

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

nandoflorestan
Copy link

While trying to make a Python validation library work in the browser, I thought I'd prefer not to change the library and just pay for it with 25 lines in Transcrypt.

I thought this simple implementation of defaultdict would work, but Firefox complains:

Uncaught TypeError: meta is undefined
__class__ org.transcrypt.__runtime__.py:4
<anonymous> collections.py:4

I suppose dict is not a Python class in Transcrypt -- is it just a JS object?

In any case, please let me know what's going on and give me a north.

This is not working yet. Firefox complains:

    Uncaught TypeError: meta is undefined
    __class__ org.transcrypt.__runtime__.py:4
    <anonymous> collections.py:4
@JennaSys
Copy link
Collaborator

JennaSys commented Jun 7, 2021

I think I've seen it mentioned in the Transcrypt docs somewhere, but on the JavaScript side, dict is just a JS object with extra properties and methods tacked on to it. Depending on what's happening on the JS side, these extra methods and properties can get "lost" and the JS pseudo-dict gets turned back into a plain JS object. I have this happen a lot when the object is being passed in to a function as a parameter (such as in the case with React props). I'm not sure if this is related to what is happening in your case or not.

On the Python side, if you are just directly accessing the dict elements it works fine anyway. But if you need to use dict methods, I've worked around it by adding a dict() cast before trying to use the object on the Python side. This forces the methods and properties to be appended to the JS object right before you need to call them.

@nandoflorestan
Copy link
Author

@JennaSys

Thank you very much for helping out. I don't think that is the issue here because the Firefox exception happens when I try to instantiate a defaultdict -- it might be that Transcrypt is not prepared to let anyone subclass dict.

The game continues...

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

Successfully merging this pull request may close these issues.

None yet

2 participants