コード例 #1
0
ファイル: object_types.py プロジェクト: JayShenoy/scenic
    def __init_subclass__(cls):
        # find all defaults provided by the class or its superclasses
        allDefs = collections.defaultdict(list)
        for sc in inspect.getmro(cls):
            if hasattr(sc, '__annotations__'):
                for prop, value in sc.__annotations__.items():
                    allDefs[prop].append(PropertyDefault.forValue(value))

        # resolve conflicting defaults
        resolvedDefs = {}
        for prop, defs in allDefs.items():
            primary, rest = defs[0], defs[1:]
            spec = primary.resolveFor(prop, rest)
            resolvedDefs[prop] = spec
        cls.defaults = resolvedDefs
コード例 #2
0
ファイル: object_types.py プロジェクト: shr-project/Scenic
    def defaults(cla):  # TODO improve so this need only be done once?
        # find all defaults provided by the class or its superclasses
        allDefs = collections.defaultdict(list)
        for sc in inspect.getmro(cla):
            if hasattr(sc, '__annotations__'):
                for prop, value in sc.__annotations__.items():
                    allDefs[prop].append(PropertyDefault.forValue(value))

        # resolve conflicting defaults
        resolvedDefs = {}
        for prop, defs in allDefs.items():
            primary, rest = defs[0], defs[1:]
            spec = primary.resolveFor(prop, rest)
            resolvedDefs[prop] = spec
        return resolvedDefs
コード例 #3
0
ファイル: object_types.py プロジェクト: t27/Scenic
    def __init_subclass__(cls):
        super().__init_subclass__()
        # find all defaults provided by the class or its superclasses
        allDefs = collections.defaultdict(list)
        for sc in cls.__mro__:
            if issubclass(sc, _Constructible) and hasattr(
                    sc, '__annotations__'):
                for prop, value in sc.__annotations__.items():
                    allDefs[prop].append(PropertyDefault.forValue(value))

        # resolve conflicting defaults and gather dynamic properties
        resolvedDefs = {}
        dyns = []
        for prop, defs in allDefs.items():
            primary, rest = defs[0], defs[1:]
            spec = primary.resolveFor(prop, rest)
            resolvedDefs[prop] = spec

            if any(defn.isDynamic for defn in defs):
                dyns.append(prop)
        cls._defaults = resolvedDefs
        cls._dynamicProperties = tuple(dyns)