Closed lijunsong closed 11 years ago
We are not yet supporting __dict__
. Forget about assigning, we can't even read it.
class F:
def __init__(self, name):
self.name = name
m = F("a")
print(m.__dict__)
will fail too.
Do you guys need dict for modules? It's good to know what we don't have, just wondering if it makes you stuck.
On Tue, Jan 8, 2013 at 9:00 PM, Anand Chitipothu notifications@github.comwrote:
We are not yet supporting dict. Forget about assigning, we can't even read it.
class F: def init(self, name): self.name = name
m = F("a") print(m.dict)
will fail too.
— Reply to this email directly or view it on GitHubhttps://github.com/brownplt/lambda-py/issues/24#issuecomment-12028031.
I think we have some sort of dict:
To be more concrete: the value, env and some parts of the store is:
value:
a
{x: 3}
env:
'(#hash((list . 10)
(abs . 23)
(max . 21)
(min . 20)
(print . 25)
(range . 55)
(filter . 56)
(str . 9)
(dict . 13)
(num . 6)
(iter . 50)
(open . 17)
(set . 15)
(bool . 14)
(object . 4)
(super . 29)
(Exception . 30)
(tuple . 11)
(callable . 28)
(m . 213)
(isinstance . 24)
(True . 1)
(float . 8)
(None . 3)
(False . 2)
(int . 7)
(next . 22)
($module . 18)
($dict . 12)
(len . 19)
(TypeError . 32)
($exec_to_dict . 27)
(__import__ . 26)
(NameError . 31)
(RuntimeError . 36)
(SyntaxError . 34)
(ValueError . 33)
(AttributeError . 35)
(ZeroDivisionError . 40)
(KeyError . 37)
(UnboundLocalError . 39)
(IndexError . 38)
(___assertFalse . 44)
(___assertEqual . 42)
(StopIteration . 41)
(___assertTrue . 43)
(___assertNotIn . 48)
(___assertIsNot . 46)
(___assertIs . 45)
(___assertIn . 47)
(all . 53)
(SeqIter . 52)
(___fail . 49)
(FuncIter . 51)
(F . 58)
(dicteq . 57)
(any . 54)
(file . 16)
(none . 5)))
useful fragment of store:
214
(VObject
'$dict
(some
(MetaDict
(hash
(VObject 'str (some (MetaStr "x")) '#hash())
(VObject 'int (some (MetaNum 3)) '#hash()))))
'#hash())
213
(VObject 'F (none) '#hash((name . 212) (__dict__ . 214)))
212
(VObject 'str (some (MetaStr "a")) '#hash())
update: Oh, right. we don't have dict, it is treated as normal attribute...
We don't need __dict__
, but we need a way to represent object-dict
type as object. I'm working on implementing a simpledict
type and MetaSimpleDict
that can be used to represent globals as an object and I'll use that in module type.
@jpolitz
we(well, I) plan to use dict to update module object.
in Python, we can use
exec(module_code, module_object.__dict__)
to import module_code to the scope module_object. Anyway, if Anand can use another way to do it, I think I will need another way to work out it.
@jpolitz both of us decided to work on it independently and compare the implementations and take the best of both.
our interpreter prints:
the
name
field of object m shouldn't exist anymore because of the assignment of its__dict__
.