sgzwiz / brython

Automatically exported from code.google.com/p/brython
BSD 3-Clause "New" or "Revised" License
0 stars 1 forks source link

Some issues with current class implementation (1.0.20130112-105851) #46

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
1. Missing static members (and their lookup ?)

class A:
    COUNTER = 0
    def __init__(self):
        self.COUNTER += 1

a = A()

Fails with COUNTER is not found since
in generated javascript, COUNTER is not set to A class.

2. Cannot set attribute on class
   (failed attempt to get around first issue)

class A:
    def __init__(self):
        self.COUNTER += 1

A.COUNTER = 0 # fails setattr missing

a = A()

3. Methods appearing in class and instance attributes
class A:
    def __init__(self):
        self.x = 1
        self.y = 1

a = A()
print(dir(a))
print(dir(A))

Output:
['__class__','__getattr__','__init__','__setattr__','__str__','toString','x','y'
]
['__class__','__eq__','__getattr__','get_name']

From my point of view:
- 'toString' and 'get_name'shall not appear
- '__init__' is missing in class

Compare to python output:
- 2.7.1
    ['__doc__', '__init__', '__module__', 'x', 'y']
    ['__doc__', '__init__', '__module__']
- 3.1.2
['__class__', '__delattr__', '__dict__', '__doc__', '__eq__', '__format__', 
'__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__le__', 
'__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', 
'__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 
'__weakref__', 'x', 'y']
['__class__', '__delattr__', '__dict__', '__doc__', '__eq__', '__format__', 
'__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__le__', 
'__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', 
'__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 
'__weakref__']

4. isinstance not working for class instances
class A:
   pass

a = A()

print( isinstance(a, A) )
Result: False

print( a.__class__ == A )
Result: False

Original issue reported on code.google.com by pedro.ro...@gmail.com on 13 Jan 2013 at 10:31

GoogleCodeExporter commented 9 years ago

Original comment by pierre.q...@gmail.com on 14 Jan 2013 at 9:52

GoogleCodeExporter commented 9 years ago
First issue fixed in revision 404

Original comment by pierre.q...@gmail.com on 15 Jan 2013 at 8:25

GoogleCodeExporter commented 9 years ago
Issue #4 fixed in revision 405

Original comment by pierre.q...@gmail.com on 15 Jan 2013 at 8:31