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

Fixed children retrieving from python collections by javascript. #3

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

Conversation

desertkun
Copy link

I've stuck with a problem recently with python collections and accessing them from javascript.

Say you have a JSON object (python dict)

{
    "a": 5, 
    "b": 10, 
    "items": [1, 2, 3]
}

When you pass it to javascript, it has a problem accessing some fields from it.
For example, if you would like to print whole python dict from javascript, it prints OK, but if you try to access some childs, corresponding methods may be returned instead.

For example, dict has a method items. So if you try to access dict["items"] from javascript, you will end up with a reference to such method, instead of child with name "items".

This pull request reverses the order of querying items from python object: first, if the object is a python collection, it tries to pull that item. Then, a corresponding field is tried to be pulled.

I understand that there would be no way to access function dict.items from now on, if there's a child with such name. But this problem only occurs to python collections, and this method is kinda useless since for (var i in dict) gives what you want. Also, printing whole dict returns childs instead of methods, so return [1, 2, 3] instead of [Function function] should be kinda expected result.

If python collection had a method with a name of the item that was requested, such method reference returned instead.
@buffer
Copy link
Owner

buffer commented Feb 16, 2017

@flier the patch is ok for me but a comment from you would be appreciated before merging. Thanks!

@buffer buffer assigned buffer and unassigned buffer Feb 17, 2017
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