Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

支持直接在代码中声明方法属性的同步作用域等特性,可以不写def文件 #612

Open
kebiao opened this issue May 5, 2018 · 3 comments
Assignees
Milestone

Comments

@kebiao
Copy link
Collaborator

kebiao commented May 5, 2018

1: 考虑客户端部分怎么办, 服务器项目没有相应的客户端部分代码无法分析
2:每个进程分析代码时必须考虑到其他进程, 例如同名属性和同名方法要限制

对应的服务器demo:https://github.com/kbengine/kbengine_demos_assets/tree/py_entity_def

@kebiao kebiao added this to the 2.0 milestone May 5, 2018
@kebiao kebiao self-assigned this May 5, 2018
@hubber83
Copy link

hubber83 commented May 8, 2018

def属性描述文件确实太繁琐了,简化是好事
如果能像c#那样加属性标签就好

@mofish9
Copy link

mofish9 commented May 9, 2018

method可以考虑使用decorator来修饰作限制

@kebiao
Copy link
Collaborator Author

kebiao commented Jan 14, 2019

考虑如下支持实现:

import inspect

class Def:
    """
    ddddd
    """
    ALL_CLIENTS = 1
    UNIQUE = 1

    thisclass = "thisclass"

    @staticmethod
    def fixed_dict(*args, **kwargs):
        def call(func):
            print("+++++++++++++++++++++++++++++++++++++++++%s" % (dir()))
            print("--------------------Def.fixed_dict: %s" % func.__qualname__)
            return func
        return call

    @staticmethod
    def fixed_array(*args, **kwargs):
        def call(func):
            print("--------------------Def.fixed_array: %s" % func.__qualname__)
            return func
        return call

    @staticmethod
    def rename(*args, **kwargs):
        """
        fdsfdsff22332
        """
        if len(kwargs) > 0:
            print("**********************************************" ,kwargs)
            return

        def call(func):
            print(type(0))
            print("--------------------Def.type: %s" % func.__qualname__)
            return func
        return call

    @staticmethod
    def fixed_item(*args, **kwargs):
        def call(func):
            print("--------------------Def.fixed_item: %s" % func.__qualname__)
            return func
        return call

    @staticmethod
    def property(*args, **kwargs):
        def call(func):
            print("--------------------Def.property: %s" % func.__qualname__)
            return func
        return call

    @staticmethod
    def method(*args, **kwargs):
        """
        fdsfdsaf
        """
        def call(func1):
            """
            fdsfdsaf1
            """
            print(inspect.getfullargspec(func1))
            print("--------------------Def.method: %s--args=%s" % (func1.__qualname__,kwargs))
            return func1
        return call

    @staticmethod
    def clientmethod(*args, **kwargs):
        def call(func):
            print(inspect.getfullargspec(func))
            print("--------------------Def.clientmethod: %s--args=%s" % (func.__qualname__,args))
            return func
        return call

    @staticmethod
    def entity(*args, **kwargs):
        def call(func):
            print("--------------------Def.entity: %s---%s" % (func.__qualname__, func.__bases__))
            return func
        return call

    @staticmethod
    def interface(*args, **kwargs):
        def call(func):
            print("--------------------Def.interface: %s" % func.__qualname__)
            return func
        return call

    @staticmethod
    def component(*args, **kwargs):
        def call(func):
            print("--------------------Def.component: %s" % func.__qualname__)
            return func
        return call

@Def.rename()
def ENTITY_ID() -> int: pass

Def.rename(ENTITY_ID=int)

@Def.fixed_array()
class XXArray(list):
    @Def.fixed_item
    def INT32(self) -> int:
        return 0

@Def.fixed_dict(implementedBy=Def.thisclass)
class XXDict(dict):
    @Def.fixed_item
    def arg1(self) -> XXArray:
        return []
    
    @Def.fixed_item()
    def arg2(self) -> str:
        return "None"

    def createObjFromDict(self, dct):
        return dct

    def getDictFromObj(self, obj):
        return obj

    def isSameType(self, obj):
        return isinstance(obj, XXDict)

@Def.entity()
class TestParent:
    def __init__(self):
        pass

    @Def.property(1)
    def prop1(self) -> int:
        return 0

@Def.interface()
class testinterface:
    @Def.property()
    def prop2(self) -> int:
        return 0

@Def.component()
class testComponent:
    @Def.property()
    def prop3(self) -> int:
        return 0

@Def.entity(hasClient=True)
class Test(TestParent, testinterface):
    def __init__(self):
        self.method1(1,2,3)

    @Def.property(2222)
    def comp_prop(self) -> testComponent:
        return 0

    @Def.property(persistent=True, flags=Def.ALL_CLIENTS, index=Def.UNIQUE, databaseLength=32)
    def prop(self) -> int:
        return 0

    @Def.method(exposed=True)
    def method1(self, b:int, a:str, c:XXArray):
        print("method1",a,b,c)

    @Def.clientmethod()
    def cli_method(self, b:int):
        pass

    @Def.method(111,22,33)
    def method2(self):
        print("method2")

    @Def.method("test")
    def method3(self):
        print("method2")

Test()

@kebiao kebiao changed the title 去掉def文件,直接在代码中声明方法属性的同步作用域等特性 支持直接在代码中声明方法属性的同步作用域等特性,可以不写def文件 Jan 15, 2019
kebiao added a commit that referenced this issue Feb 1, 2019
kebiao added a commit that referenced this issue Feb 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants