1
0
Fork 0
mirror of https://github.com/yweber/lodel2.git synced 2026-07-29 01:03:28 +02:00

Bugfixes in lefactory and letype

Deleted the classinstancemethod decorator because of inheritance problems (not sure they were real...)
Add a shortcut method to LeFactory to get the generated LeObject class
+ bugfixes
This commit is contained in:
Yann 2015-10-23 15:52:35 +02:00
commit 052ddd4ce8
3 changed files with 20 additions and 88 deletions

View file

@ -1,44 +0,0 @@
#-*- coding: utf-8 -*-
## @brief Decorator to have methods with the same name callable from Class or from Instance
#
# Usage example :
# @code{.py}
# class A(object):
# @classinstancemethod
# def foo(self, a, b):
# print("foo() instance call", a ,b)
#
# @foo.classmethod
# def foo(self):
# print("foo() class call")
#
# @classinstancemethod
# def bar(obj):
# if obj == A:
# print("bar() class call")
# else:
# print("bar() instance call")
#
# a=A()
# A.foo() #foo() class call
# a.foo(1,2) #foo() instance call 1 2
# A.bar() #bar() class call
# a.bar() #bar() instance call
# @endcode
class classinstancemethod(object):
def __init__(self, func):
self._func = func
self._classmethod = None
def classmethod(self, func):
self._classmethod = func
def __get__(self, instance, cls):
if instance is None:
if self._classmethod is None:
return self._func.__get__(cls, cls)
else:
return self._classmethod.__get__(instance, cls)
else:
return self._func.__get__(instance, cls)