当前位置: 首页>>代码示例>>Python>>正文


Python inspect.isdatadescriptor方法代码示例

本文整理汇总了Python中inspect.isdatadescriptor方法的典型用法代码示例。如果您正苦于以下问题:Python inspect.isdatadescriptor方法的具体用法?Python inspect.isdatadescriptor怎么用?Python inspect.isdatadescriptor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在inspect的用法示例。


在下文中一共展示了inspect.isdatadescriptor方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_excluding_predicates

# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import isdatadescriptor [as 别名]
def test_excluding_predicates(self):
        self.istest(inspect.isbuiltin, 'sys.exit')
        self.istest(inspect.isbuiltin, '[].append')
        self.istest(inspect.iscode, 'mod.spam.func_code')
        self.istest(inspect.isframe, 'tb.tb_frame')
        self.istest(inspect.isfunction, 'mod.spam')
        self.istest(inspect.ismethod, 'mod.StupidGit.abuse')
        self.istest(inspect.ismethod, 'git.argue')
        self.istest(inspect.ismodule, 'mod')
        self.istest(inspect.istraceback, 'tb')
        self.istest(inspect.isdatadescriptor, '__builtin__.file.closed')
        self.istest(inspect.isdatadescriptor, '__builtin__.file.softspace')
        self.istest(inspect.isgenerator, '(x for x in xrange(2))')
        self.istest(inspect.isgeneratorfunction, 'generator_function_example')
        if hasattr(types, 'GetSetDescriptorType'):
            self.istest(inspect.isgetsetdescriptor,
                        'type(tb.tb_frame).f_locals')
        else:
            self.assertFalse(inspect.isgetsetdescriptor(type(tb.tb_frame).f_locals))
        if hasattr(types, 'MemberDescriptorType'):
            self.istest(inspect.ismemberdescriptor, 'datetime.timedelta.days')
        else:
            self.assertFalse(inspect.ismemberdescriptor(datetime.timedelta.days)) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:25,代码来源:test_inspect.py

示例2: test_excluding_predicates

# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import isdatadescriptor [as 别名]
def test_excluding_predicates(self):
        #self.istest(inspect.isbuiltin, 'sys.exit')  # Not valid for Jython
        self.istest(inspect.isbuiltin, '[].append')
        self.istest(inspect.iscode, 'mod.spam.func_code')
        self.istest(inspect.isframe, 'tb.tb_frame')
        self.istest(inspect.isfunction, 'mod.spam')
        self.istest(inspect.ismethod, 'mod.StupidGit.abuse')
        self.istest(inspect.ismethod, 'git.argue')
        self.istest(inspect.ismodule, 'mod')
        self.istest(inspect.istraceback, 'tb')
        self.istest(inspect.isdatadescriptor, '__builtin__.file.closed')
        self.istest(inspect.isdatadescriptor, '__builtin__.file.softspace')
        self.istest(inspect.isgenerator, '(x for x in xrange(2))')
        self.istest(inspect.isgeneratorfunction, 'generator_function_example')
        if hasattr(types, 'GetSetDescriptorType'):
            self.istest(inspect.isgetsetdescriptor,
                        'type(tb.tb_frame).f_locals')
        else:
            self.assertFalse(inspect.isgetsetdescriptor(type(tb.tb_frame).f_locals))
        if hasattr(types, 'MemberDescriptorType'):
            # Not valid for Jython
            # self.istest(inspect.ismemberdescriptor, 'datetime.timedelta.days')
            pass
        else:
            self.assertFalse(inspect.ismemberdescriptor(datetime.timedelta.days)) 
开发者ID:Acmesec,项目名称:CTFCrackTools-V2,代码行数:27,代码来源:test_inspect.py

示例3: __init__

# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import isdatadescriptor [as 别名]
def __init__(cls, name, bases, dct):
        def is_public_member(key):
            return (
                (key.startswith('__') and key.endswith('__')
                 and len(key) > 4) or
                not key.startswith('_'))

        for key, val in dct.items():
            if ((inspect.isfunction(val) or inspect.isdatadescriptor(val)) and
                    is_public_member(key) and
                    val.__doc__ is None):
                for base in cls.__mro__[1:]:
                    super_method = getattr(base, key, None)
                    if super_method is not None:
                        val.__doc__ = super_method.__doc__
                        break

        super().__init__(name, bases, dct) 
开发者ID:holzschu,项目名称:Carnets,代码行数:20,代码来源:misc.py

示例4: classify_class_attrs

# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import isdatadescriptor [as 别名]
def classify_class_attrs(object):
    """Wrap inspect.classify_class_attrs, with fixup for data descriptors."""
    results = []
    for (name, kind, cls, value) in inspect.classify_class_attrs(object):
        if inspect.isdatadescriptor(value):
            kind = 'data descriptor'
        results.append((name, kind, cls, value))
    return results

# ----------------------------------------------------- module manipulation 
开发者ID:war-and-code,项目名称:jawfish,代码行数:12,代码来源:pydoc.py

示例5: _get_exposed_property_value

# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import isdatadescriptor [as 别名]
def _get_exposed_property_value(obj: Any, propname: str, only_exposed: bool = True) -> Any:
    """
    Return the value of an @exposed @property.
    If the requested property is not a @property or not exposed,
    an AttributeError is raised instead.
    """
    v = getattr(obj.__class__, propname)
    if inspect.isdatadescriptor(v):
        if v.fget and getattr(v.fget, "_pyroExposed", not only_exposed):
            return v.fget(obj)
    raise AttributeError("attempt to access unexposed or unknown remote attribute '%s'" % propname) 
开发者ID:irmen,项目名称:Pyro5,代码行数:13,代码来源:server.py

示例6: _set_exposed_property_value

# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import isdatadescriptor [as 别名]
def _set_exposed_property_value(obj: Any, propname: str, value: Any, only_exposed: bool = True) -> Any:
    """
    Sets the value of an @exposed @property.
    If the requested property is not a @property or not exposed,
    an AttributeError is raised instead.
    """
    v = getattr(obj.__class__, propname)
    if inspect.isdatadescriptor(v):
        pfunc = v.fget or v.fset or v.fdel
        if v.fset and getattr(pfunc, "_pyroExposed", not only_exposed):
            return v.fset(obj, value)
    raise AttributeError("attempt to access unexposed or unknown remote attribute '%s'" % propname) 
开发者ID:irmen,项目名称:Pyro5,代码行数:14,代码来源:server.py

示例7: classify_class_attrs

# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import isdatadescriptor [as 别名]
def classify_class_attrs(object):
    """Wrap inspect.classify_class_attrs, with fixup for data descriptors."""
    def fixup(data):
        name, kind, cls, value = data
        if inspect.isdatadescriptor(value):
            kind = 'data descriptor'
        return name, kind, cls, value
    return map(fixup, inspect.classify_class_attrs(object))

# ----------------------------------------------------- module manipulation 
开发者ID:glmcdona,项目名称:meddle,代码行数:12,代码来源:pydoc.py

示例8: classify_class_attrs

# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import isdatadescriptor [as 别名]
def classify_class_attrs(object):
    """Wrap inspect.classify_class_attrs, with fixup for data descriptors."""
    def fixup(data):
        name, kind, cls, value = data
        if inspect.isdatadescriptor(value):
            kind = 'data descriptor'
        return name, kind, cls, value
    return map(fixup, inspect.classify_class_attrs(object))

# ----------------------------------------------------- Unicode support helpers 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:12,代码来源:pydoc.py

示例9: bind

# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import isdatadescriptor [as 别名]
def bind(self, target):
        if self.func not in dir(target):
            return None

        funcs = []

        if self.read_pattern is not None:
            def getter():
                return getattr(target, self.func)

            # Copy docstring if target is a @property
            prop = getattr(type(target), self.func, None)
            if prop and inspect.isdatadescriptor(prop):
                getter.__doc__ = 'Getter: ' + inspect.getdoc(prop)

            funcs.append(
                Func(getter, self.read_pattern, return_mapping=self.return_mapping, doc=self.doc))

        if self.write_pattern is not None:
            def setter(new_value):
                setattr(target, self.func, new_value)

            # Copy docstring if target is a @property
            prop = getattr(type(target), self.func, None)
            if prop and inspect.isdatadescriptor(prop):
                setter.__doc__ = 'Setter: ' + inspect.getdoc(prop)

            funcs.append(
                Func(setter, self.write_pattern, argument_mappings=self.argument_mappings,
                     return_mapping=self.return_mapping, doc=self.doc))

        return funcs 
开发者ID:ess-dmsc,项目名称:lewis,代码行数:34,代码来源:stream.py

示例10: _extract_props

# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import isdatadescriptor [as 别名]
def _extract_props(cls):
        return map(lambda e: e[0], getmembers(cls, predicate=isdatadescriptor)) 
开发者ID:christabor,项目名称:MoAL,代码行数:4,代码来源:nominal_structural.py

示例11: test_excluding_predicates

# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import isdatadescriptor [as 别名]
def test_excluding_predicates(self):
        global tb
        self.istest(inspect.isbuiltin, 'sys.exit')
        self.istest(inspect.isbuiltin, '[].append')
        self.istest(inspect.iscode, 'mod.spam.__code__')
        try:
            1/0
        except:
            tb = sys.exc_info()[2]
            self.istest(inspect.isframe, 'tb.tb_frame')
            self.istest(inspect.istraceback, 'tb')
            if hasattr(types, 'GetSetDescriptorType'):
                self.istest(inspect.isgetsetdescriptor,
                            'type(tb.tb_frame).f_locals')
            else:
                self.assertFalse(inspect.isgetsetdescriptor(type(tb.tb_frame).f_locals))
        finally:
            # Clear traceback and all the frames and local variables hanging to it.
            tb = None
        self.istest(inspect.isfunction, 'mod.spam')
        self.istest(inspect.isfunction, 'mod.StupidGit.abuse')
        self.istest(inspect.ismethod, 'git.argue')
        self.istest(inspect.ismodule, 'mod')
        self.istest(inspect.isdatadescriptor, 'collections.defaultdict.default_factory')
        self.istest(inspect.isgenerator, '(x for x in range(2))')
        self.istest(inspect.isgeneratorfunction, 'generator_function_example')

        with warnings.catch_warnings():
            warnings.simplefilter("ignore")
            self.istest(inspect.iscoroutine, 'coroutine_function_example(1)')
            self.istest(inspect.iscoroutinefunction, 'coroutine_function_example')

        if hasattr(types, 'MemberDescriptorType'):
            self.istest(inspect.ismemberdescriptor, 'datetime.timedelta.days')
        else:
            self.assertFalse(inspect.ismemberdescriptor(datetime.timedelta.days)) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:38,代码来源:test_inspect.py

示例12: test_getmembers_descriptors

# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import isdatadescriptor [as 别名]
def test_getmembers_descriptors(self):
        class A(object):
            dd = _BrokenDataDescriptor()
            md = _BrokenMethodDescriptor()

        def pred_wrapper(pred):
            # A quick'n'dirty way to discard standard attributes of new-style
            # classes.
            class Empty(object):
                pass
            def wrapped(x):
                if '__name__' in dir(x) and hasattr(Empty, x.__name__):
                    return False
                return pred(x)
            return wrapped

        ismethoddescriptor = pred_wrapper(inspect.ismethoddescriptor)
        isdatadescriptor = pred_wrapper(inspect.isdatadescriptor)

        self.assertEqual(inspect.getmembers(A, ismethoddescriptor),
            [('md', A.__dict__['md'])])
        self.assertEqual(inspect.getmembers(A, isdatadescriptor),
            [('dd', A.__dict__['dd'])])

        class B(A):
            pass

        self.assertEqual(inspect.getmembers(B, ismethoddescriptor),
            [('md', A.__dict__['md'])])
        self.assertEqual(inspect.getmembers(B, isdatadescriptor),
            [('dd', A.__dict__['dd'])]) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:33,代码来源:test_inspect.py

示例13: _get_fields

# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import isdatadescriptor [as 别名]
def _get_fields(cls, base_fields=True) -> List[JsonSchemaField]:

        def _get_fields_uncached():
            dataclass_bases = [
                klass for klass in cls.__bases__ if is_dataclass(klass) and issubclass(klass, JsonSchemaMixin)
            ]
            base_fields_types = set()
            for base in dataclass_bases:
                base_fields_types |= {(f.name, f.type) for f in fields(base)}

            mapped_fields = []
            type_hints = get_type_hints(cls)
            for f in fields(cls):
                # Skip internal fields
                if f.name.startswith("__") or (not base_fields and (f.name, f.type) in base_fields_types):
                    continue
                # Note fields() doesn't resolve forward refs
                f.type = type_hints[f.name]
                mapped_fields.append(JsonSchemaField(f, cls.field_mapping().get(f.name, f.name)))

            if cls.__serialise_properties:
                include_properties = None
                if isinstance(cls.__serialise_properties, tuple):
                    include_properties = set(cls.__serialise_properties)

                members = inspect.getmembers(cls, inspect.isdatadescriptor)
                for name, member in members:
                    if name != "__weakref__" and (include_properties is None or name in include_properties):
                        f = Field(MISSING, None, None, None, None, None, None)
                        f.name = name
                        f.type = member.fget.__annotations__['return']
                        mapped_fields.append(JsonSchemaField(f, name, is_property=True))

            return mapped_fields

        if not base_fields:
            return _get_fields_uncached()

        if not cls.__mapped_fields:
            cls.__mapped_fields = _get_fields_uncached()
        return cls.__mapped_fields  # type: ignore 
开发者ID:s-knibbs,项目名称:dataclasses-jsonschema,代码行数:43,代码来源:__init__.py

示例14: classify_class_attrs

# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import isdatadescriptor [as 别名]
def classify_class_attrs(object):
    """Wrap inspect.classify_class_attrs, with fixup for data descriptors."""
    results = []
    for (name, kind, cls, value) in inspect.classify_class_attrs(object):
        if inspect.isdatadescriptor(value):
            kind = 'data descriptor'
        results.append((name, kind, cls, value))
    return results 
开发者ID:CedricGuillemet,项目名称:Imogen,代码行数:10,代码来源:pydoc.py

示例15: is_descriptor

# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import isdatadescriptor [as 别名]
def is_descriptor(self) -> bool:
        """Determine if initial method provided is a descriptor."""
        method = self.methods[0][0]
        instance = self._get_instance(method)
        if instance:
            attr = inspect.getattr_static(instance, self._name)
            return inspect.isdatadescriptor(attr)
        return False 
开发者ID:BradenM,项目名称:micropy-cli,代码行数:10,代码来源:modules.py


注:本文中的inspect.isdatadescriptor方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。