support for built-in function vars()

The official pyboard running MicroPython.
This is the reference design and main target board for MicroPython.
You can buy one at the store.
Target audience: Users with a pyboard.
amar123deep
Posts: 12
Joined: Tue Sep 27, 2016 2:29 pm

support for built-in function vars()

Post by amar123deep » Thu Sep 29, 2016 12:51 pm

Hi, I am new to Micropython. Currently working on porting middleware named "calvin" from Ericsson on micropython platform. I came across a problem due to wrapt library that uses vars() bult-in function. Are you planning to provide the functionality? Any hint how to get around this?

Thanks in advance for the reply!

amar123deep
Posts: 12
Joined: Tue Sep 27, 2016 2:29 pm

Error while using __get__ in a class

Post by amar123deep » Thu Sep 29, 2016 1:17 pm

Hi, I am getting an error "AttributeError: 'function' object has no attribute '__get__' on calling "__get__" method of a class. Any help?

User avatar
platforma
Posts: 258
Joined: Thu May 28, 2015 5:08 pm
Location: Japan

Re: Error while using __get__ in a class

Post by platforma » Thu Sep 29, 2016 3:59 pm

Perhaps a description of what object, of which class, from which module you're trying to use etc., would be helpful. A short description of what your code is trying to achieve and a code snippet would be of even more assistance! It is difficult to say what you're trying to do just from what you've written alone.

User avatar
deshipu
Posts: 1388
Joined: Thu May 28, 2015 5:54 pm

Re: support for built-in function vars()

Post by deshipu » Fri Sep 30, 2016 7:00 am

I can't speak for all the developers, but if you look at point 8 at https://github.com/micropython/micropyt ... ifferences you will see, that this omission is one of the more important differences from cpython, and it seems like it would require quite some work (and lost performance) to implement it.

User avatar
deshipu
Posts: 1388
Joined: Thu May 28, 2015 5:54 pm

Re: support for built-in function vars()

Post by deshipu » Fri Sep 30, 2016 7:00 am

What is that program using `vars()` for?

User avatar
deshipu
Posts: 1388
Joined: Thu May 28, 2015 5:54 pm

Re: Error while using __get__ in a class

Post by deshipu » Fri Sep 30, 2016 7:05 am

Are you sure you are creating a class (using the "class" keyword) and not a function (using the "def" keyword)? I've seen that error before...

amar123deep
Posts: 12
Joined: Tue Sep 27, 2016 2:29 pm

Re: Error while using __get__ in a class

Post by amar123deep » Fri Sep 30, 2016 8:17 am

Well, I think the error is because I can not assign attribute to function object. For example

Code: Select all

>>> def f():
...     pass
>>> f.a = 1
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'function' object has no attribute 'a'
please make use of the code blocks :) - platforma

Why I wanted this feature, because the middleware that I am trying to port on micropython, uses wrapt decorator to get information about the calling instance of a class. wrapt uses vars() built.in which also not supported by micropython. Then I wrote a class decorator that uses __get__ descriptor to know the information about the calling instance of the wrapped method.
For more info, one can follow the link: http://blog.dscpl.com.au/2014/01/implem ... r.html?m=1

Any help will be really appreciable!

amar123deep
Posts: 12
Joined: Tue Sep 27, 2016 2:29 pm

Re: support for built-in function vars()

Post by amar123deep » Fri Sep 30, 2016 8:21 am

I replied in another thread that the middleware that I want to port on micropython uses wrapt package (https://pypi.python.org/pypi/wrapt). And wrapt internally uses vars().

User avatar
platforma
Posts: 258
Joined: Thu May 28, 2015 5:08 pm
Location: Japan

Re: support for built-in function vars()

Post by platforma » Fri Sep 30, 2016 8:25 am

The topics are now merged.

amar123deep
Posts: 12
Joined: Tue Sep 27, 2016 2:29 pm

Re: support for built-in function vars()

Post by amar123deep » Fri Sep 30, 2016 8:35 am

Thanks! Just wanted to give a brief info about the project. The idea is to run calvin on micropython for IoT applications. Calvin is a middleware and provides actor-based programming model to ease developers from complexity of distributed computing. One can follow https://github.com/EricssonResearch/calvin-base for more info.

Post Reply