brownplt / lambda-py

Other
58 stars 10 forks source link

class type has no attribute __dict__ #53

Closed mpmilano closed 11 years ago

mpmilano commented 11 years ago

Classes should have a dict, but they don't in rython. This is the only thing preventing the test nonlocal-class.py from working.

amtriathlon commented 11 years ago

With the new attribute regime a snapshot dict attribute would be easy to add having an obj-dict primitive (or CDir expression, the same which is needed to implement dir(obj)),. A dynamic dict reflecting updates in both ways would be far more complicated but, a nice feature to have.

2013/3/24 Matthew Milano notifications@github.com

Classes should have a dict, but they don't in rython. This is the only thing preventing the test nonlocal-class.py from working.

— Reply to this email directly or view it on GitHubhttps://github.com/brownplt/lambda-py/issues/53 .

Alejandro.

jpolitz commented 11 years ago

dict should return a dictionary with a special setitem that performs attribute update... would that work?

On Sun, Mar 24, 2013 at 12:24 PM, Alejandro Martinez < notifications@github.com> wrote:

With the new attribute regime a snapshot dict attribute would be easy to add having an obj-dict primitive (or CDir expression, the same which is needed to implement dir(obj)),. A dynamic dict reflecting updates in both ways would be far more complicated but, a nice feature to have.

2013/3/24 Matthew Milano notifications@github.com

Classes should have a dict, but they don't in rython. This is the only thing preventing the test nonlocal-class.py from working.

— Reply to this email directly or view it on GitHub< https://github.com/brownplt/lambda-py/issues/53> .

Alejandro.

— Reply to this email directly or view it on GitHubhttps://github.com/brownplt/lambda-py/issues/53#issuecomment-15361905 .

amtriathlon commented 11 years ago

Yes, this would solve the way dict["a"] = x -> obj.a = x, for the other direction that dictionary should have also a special getitem that performs attribute lookup on the object.

2013/3/24 Joe Politz notifications@github.com

dict should return a dictionary with a special setitem that performs attribute update... would that work?

On Sun, Mar 24, 2013 at 12:24 PM, Alejandro Martinez < notifications@github.com> wrote:

With the new attribute regime a snapshot dict attribute would be easy to add having an obj-dict primitive (or CDir expression, the same which is needed to implement dir(obj)),. A dynamic dict reflecting updates in both ways would be far more complicated but, a nice feature to have.

2013/3/24 Matthew Milano notifications@github.com

Classes should have a dict, but they don't in rython. This is the only thing preventing the test nonlocal-class.py from working.

— Reply to this email directly or view it on GitHub< https://github.com/brownplt/lambda-py/issues/53> .

Alejandro.

— Reply to this email directly or view it on GitHub< https://github.com/brownplt/lambda-py/issues/53#issuecomment-15361905> .

— Reply to this email directly or view it on GitHubhttps://github.com/brownplt/lambda-py/issues/53#issuecomment-15362007 .

Alejandro.

amtriathlon commented 11 years ago

I think a dict whose internaldict is a computed attribute (from the oject internal dict) and setitem perfoms attribute update could be a nice solution.

2013/3/24 Alejandro Martinez amtriathlon@gmail.com

Yes, this would solve the way dict["a"] = x -> obj.a = x, for the other direction that dictionary should have also a special getitem that performs attribute lookup on the object.

2013/3/24 Joe Politz notifications@github.com

dict should return a dictionary with a special setitem that performs attribute update... would that work?

On Sun, Mar 24, 2013 at 12:24 PM, Alejandro Martinez < notifications@github.com> wrote:

With the new attribute regime a snapshot dict attribute would be easy to add having an obj-dict primitive (or CDir expression, the same which is needed to implement dir(obj)),. A dynamic dict reflecting updates in both ways would be far more complicated but, a nice feature to have.

2013/3/24 Matthew Milano notifications@github.com

Classes should have a dict, but they don't in rython. This is the only thing preventing the test nonlocal-class.py from working.

— Reply to this email directly or view it on GitHub< https://github.com/brownplt/lambda-py/issues/53> .

Alejandro.

— Reply to this email directly or view it on GitHub< https://github.com/brownplt/lambda-py/issues/53#issuecomment-15361905> .

— Reply to this email directly or view it on GitHubhttps://github.com/brownplt/lambda-py/issues/53#issuecomment-15362007 .

Alejandro.

Alejandro.

amtriathlon commented 11 years ago

The update part is necessary only for instances, for classes the dict is read only, so the proposed solution would be:

1) dict is a computed attributed returning a subclass of dict bound to the class object 2) that subclass of dict has overrides attribute internaldict with a computed one using obj-dir primitive operation or CDir expression. 3) that subclass of dict overrides setitem to update the object internal dict only when the object is not a class, this requires CSetAttr and could be left for the future.

Is Anyone willing to tackle the obj-dir/CDir part?

amtriathlon commented 11 years ago

I've implemented the snapshot version, it works for instances and class objects, and added a simple regression test, I think it is too late to start with the dynamic version, at least for me.

jpolitz commented 11 years ago

It's fine to stop there for now. Thanks!

On Mon, Mar 25, 2013 at 7:16 PM, Alejandro Martinez < notifications@github.com> wrote:

I've implemented the snapshot version, it works for instances and class objects, and added a simple regression test, I think it is too late to start with the dynamic version, at least for me.

— Reply to this email directly or view it on GitHubhttps://github.com/brownplt/lambda-py/issues/53#issuecomment-15431749 .

jpolitz commented 11 years ago

I'd say, if you want to do anything still, go hunt down some tests that we can pass now and move them over. I'd even prefer this to you figuring out my bug in the other thread :-)

On Mon, Mar 25, 2013 at 7:18 PM, Joe Gibbs Politz joe@cs.brown.edu wrote:

It's fine to stop there for now. Thanks!

On Mon, Mar 25, 2013 at 7:16 PM, Alejandro Martinez < notifications@github.com> wrote:

I've implemented the snapshot version, it works for instances and class objects, and added a simple regression test, I think it is too late to start with the dynamic version, at least for me.

— Reply to this email directly or view it on GitHubhttps://github.com/brownplt/lambda-py/issues/53#issuecomment-15431749 .

amtriathlon commented 11 years ago

I just come back to home, regression test have finished ok so I pushed the commit but, I couldn't look at the bug yet, sorry! It is in my pending list, together with dir which is within reach now, and looking for some more tests...

2013/3/25 Joe Politz notifications@github.com

I'd say, if you want to do anything still, go hunt down some tests that we can pass now and move them over. I'd even prefer this to you figuring out my bug in the other thread :-)

On Mon, Mar 25, 2013 at 7:18 PM, Joe Gibbs Politz joe@cs.brown.edu wrote:

It's fine to stop there for now. Thanks!

On Mon, Mar 25, 2013 at 7:16 PM, Alejandro Martinez < notifications@github.com> wrote:

I've implemented the snapshot version, it works for instances and class objects, and added a simple regression test, I think it is too late to start with the dynamic version, at least for me.

— Reply to this email directly or view it on GitHub< https://github.com/brownplt/lambda-py/issues/53#issuecomment-15431749> .

— Reply to this email directly or view it on GitHubhttps://github.com/brownplt/lambda-py/issues/53#issuecomment-15431856 .

Alejandro.

amtriathlon commented 11 years ago

The dynamic version was easier than I expected: the dict attribute is an object of dict_proxy class, which is a subclass of dict overriding six dict methods, I will push an update.