Skip to content

Commit

Permalink
Added metaclass test from standard test suite, Fixed attribute lookup…
Browse files Browse the repository at this point in the history
… in metaclass.
  • Loading branch information
amtriathlon committed May 28, 2013
1 parent 67ea8a1 commit 0a88d96
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 8 deletions.
4 changes: 2 additions & 2 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
This document summarizes the features added to the originally submitted version, before the artifact evaluation, and related tests.

Added support for complete Python call semantics at desugar:
Added support for general Python call semantics at desugar:
keyword arguments and **kwargs expressions
generalized defaults handling in def and lambda
keyword only arguments and **kwarg parameter in in def and lambda
Related tests in python-reference/functions: func_defaults.py, func_stararg.py, keyword_args1.py, keyword_args2.py, keyword_args3.py, keyword_args4.py, kwarg.py, kwonlyargs.py, lambda_defaults.py, lambda_stararg.py, non_tuple_stararg.py

Added support for the with statement and context manager protocol support to file class, related tests: python-reference/exceptions/test_with.py

Added support for metaclasses other than type via metaclass keyword argument and metaclass inheritance, related tests in python-reference/class: metaclass-function.py, metaclass-class1.py, metaclass-class2.py and metaclass-class3.py
Added initial support for metaclasses other than type via metaclass keyword argument and metaclass inheritance, related tests in python-reference/class: metaclass-function.py, metaclass-class1.py, metaclass-class2.py, metaclass-class3.py and test_metaclass.py

Added support for Class Decorators, related tests: class/class-decorators.py

Expand Down
1 change: 1 addition & 0 deletions base/pylib/tuple.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ def __eq__(self, other):
return cmpresult.__eq__(0)

def __hash__(self):
result = 0
for elt in self:
result += self.__hash__() * 17
return result
Expand Down
23 changes: 17 additions & 6 deletions base/pylib/type.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,25 @@ def __call__(cls, *args):
def __bool__(cls): return True

def __getattribute__(cls, key):
val = ___getattr(cls, key)
val_cls = ___delta("$class", val)
try:
get = ___getattr(val_cls, "__get__")
val = ___getattr(cls, key)
val_cls = ___delta("$class", val)
try:
get = ___getattr(val_cls, "__get__")
except:
return val
else:
return get(val, None, cls)
except:
return val
else:
return get(val, None, cls)
metaclass = ___delta("$class", cls)
val = ___getattr(metaclass, key)
val_cls = ___delta("$class", val)
try:
get = ___getattr(val_cls, "__get__")
except:
return val
else:
return get(val, cls, metaclass)

def __dir__(cls):
list = ___id("%list")
Expand Down
File renamed without changes.
32 changes: 32 additions & 0 deletions tests/python-reference/class/test_metaclass.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# test_metaclass fragment from standard Python test suite
def test_metaclass():
# Testing metaclasses...
class C(metaclass=type):
def __init__(self):
self.__state = 0
def getstate(self):
return self.__state
def setstate(self, state):
self.__state = state
a = C()
___assertEqual(a.getstate(), 0)
a.setstate(10)
___assertEqual(a.getstate(), 10)
class _metaclass(type):
def myself(cls): return cls
class D(metaclass=_metaclass):
pass
___assertEqual(D.myself(), D)
d = D()
___assertEqual(d.__class__, D)
class M1(type):
def __new__(cls, name, bases, dict):
dict['__spam__'] = 1
return type.__new__(cls, name, bases, dict)
class C(metaclass=M1):
pass
___assertEqual(C.__spam__, 1)
c = C()
___assertEqual(c.__spam__, 1)

test_metaclass()

0 comments on commit 0a88d96

Please sign in to comment.