builtin descriptor types

2023-11-15

inspect. getattr_static ( objattrdefault=None )

Retrieve attributes without triggering dynamic lookup via the descriptor protocol, __getattr__() or__getattribute__().

Note: this function may not be able to retrieve all attributes that getattr can fetch (like dynamically created attributes) and may find attributes that getattr can’t (like descriptors that raise AttributeError). It can also return descriptors objects instead of instance members.

If the instance __dict__ is shadowed by another member (for example a property) then this function will be unable to find instance members.

New in version 3.2.

getattr_static() does not resolve descriptors, for example slot descriptors or getset descriptors on objects implemented in C. The descriptor object is returned instead of the underlying attribute.

You can handle these with code like the following. Note that for arbitrary getset descriptors invoking these may trigger code execution:

# example code for resolving the builtin descriptor types
class _foo:
    __slots__ = ['foo']
slot_descriptor = type(_foo.foo)
getset_descriptor = type(type(open(__file__)).name)
wrapper_descriptor = type(str.__dict__['__add__'])
descriptor_types = (slot_descriptor, getset_descriptor, wrapper_descriptor)
result = getattr_static(some_object, 'foo')
if type(result) in descriptor_types:
    try:
        result = result.__get__()
    except AttributeError:
        # descriptors can raise AttributeError to
        # indicate there is no underlying value
        # in which case the descriptor itself will
        # have to do
        pass
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

builtin descriptor types 的相关文章

随机推荐

  • 常用bat

    1 net start XXX 用于启动系统服务 XXX 对应 系统服务中的对应的服务名称 启动mysql服务 net start MySQL 启动ORACLE服务 net start OracleServiceORCL net start
  • CRYSTAL-ubuntu-打工人使用手册-log

    个人笔记 将Mp4转换成gif sudo apt get install mplayer 将mp4分解成jpg存储到 img中 mplayer ao null result 2411 mp4 vo jpeg outdir img 将 img
  • Linux基础命令---显示进程树pstree

    pstree pstree显示正在运行的进程的树形结构 树以PID为根 如果省略了pid则以init为根 如果指定了用户名 则显示根植于该用户拥有的进程的所有进程树 如果pstree被调用为pstree x11 那么它将提示行尾的用户按RE
  • 区块链技术通俗讲解_要了解区块链一定要清楚区块链技术的几点技术原理

    关注 区链数科 让你从入门到精通区块链 其实 区块链并不是一个新型的技术 更多的应该是传统技术上的一个融合 再通过一定的规则和机制去实现了区块链独特性质 我们前面主要普及一些关于区块链的基本概念以及市场概况 今天来讲讲区块链的技术原理 希望
  • 使用pandas groupby的一个案例

    mongodb中有下面一组数据 业务场景就不介绍了 看数据应该很好理解 id 606fdd0805f5710008a82223 brand id 1 brand name APPLE series id 11 series name iPh
  • jdbc连接Microsoft SQL Server 2014

    前言 多年不用Microsoft SQL Server 简单回顾一下并记录一下在java中连接SQL Server的过程和注意事项 首先 从下载Driver开始 Microsoft JDBC Drivers 官方的下载地址为 适用于 SQL
  • 一些方便记忆的小例子

    epoll和select的小例子 先看一下epoll和select的区别 对于select来说 所有文件描述符都是在用户态被加入其文件描述符集合的 每次调用都需要将整个集合拷贝到内核态 epoll则将整个文件描述符集合维护在内核态 每次添加
  • Zookeeper缩容5缩3操作记录(二)

    测试目标 测试5台缩3台zk 先shutdown 一台5 再将1 2 3配置修改为1 2 3 逐一重启 是否会发生脑裂 测试过程 准备1 2 3 4 5 五台 3为leader 将5 shutdown 1 将1配置修改为1 2 3 重启 结
  • R语言之 删除重复数据

    这篇主要介绍如何在R中识别和删除重复数据 主要用的到R base和dplyr函数 duplicated 用于识别重复的元素和 unique 用于提取唯一元素 distinct dplyr package 删除数据框中的重复行 x lt c
  • Java:Immutable Patterns

    版权所有 2022 涂聚文有限公司 许可信息查看 描述 不变模式 Immutable Patterns 历史版本 JDK 14 02 2022 09 12 创建者 geovindu 2022 09 12 添加 Lambda 2022 09
  • 四旋翼无人机Matlab建模

    本文主要分享一下四旋翼无人机的建模过程 然后在Matlab的simulink模块搭建起四旋翼无人机的模型 本篇文章主要参考了康日晖的 四旋翼无人机建模 与南京邮电大学周帆同学的硕士毕业论文 最后我会给出参考文章网址 有兴趣的同学可以看看 一
  • 8、2D建筑与3D模型的遮挡问题 URP Shader

    在我们的实际项目中根据实际情况 我们的建筑采用了2D面片的方式 但因为我们的英雄是3D模型 同时策划有需求 英雄可以在主城里面走动 这个时候就给我们提出了一个比较麻烦的问题 我们知道正常情况下渲染是谁的渲染队列高谁渲染在上面 我们这里英雄的
  • WPF 控件库Live Charts 动态折线图

    Live Charts库安装通过 1 PM gt Install Package LiveCharts Wpf 2 通过Nuget搜索添加LiveCharts Wpf安装 WPF页面xaml
  • oracle 去除oracle字段值得tab格

    大家都知道oracle中去掉左右空格用trim 函数 单独去左空格用ltrim 去右空格用rtrim 偶尔大家从excel中复制粘贴到数据空中的数据有可能左右会存在空格或者tab 此时可以用以下语句对所有存有字段的tab进行更新update
  • linux 下 systemd-udevd 服务解析

    最近在看linux下重定向的时候看到 的这个系统的服务 所以记下来备忘 描述 systemd udevd是监听内核发出的设备事件 并根据udev规则处理每个事件 选项 daemon 脱离控制台 并作为后台守程运行 debug 在标准错误上打
  • linux shell $0怎么输出,linux shell中$0,$?,$!等的特殊用法

    一 Shell脚本中 0 等的意义说明 1 Shell本身的PID ProcessID 即脚本运行的当前进程ID号 2 Shell最后运行的后台Process的PID 后台运行的最后一个进程的 进程ID号 3 最后运行的命令的结束代码 返回
  • 【IT项目管理】第八章课后作业

    1 制定的聘用的质量标准清单如下 标准编号 标准名称 标准内容 1 年龄 30岁以上 2 学历 博士学位 3 研究成果 至少在省级以上刊物发表文章 4 工作经验 具有2年以上教师从业经验 5 项目经历 至少主持或参与省级基金项目 2 制作E
  • 【网络原理篇2】TCP报头详解

    在这一篇文章当中 了解到TCP是属于传输层的协议 当数据从应用层向传输层发送的时候 如果使用的是TCP协议 那么就需要把应用层的数据加上TCP报头 初识网络 IP 端口 网络协议 TCP IP五层模型 革凡成圣211的博客 CSDN博客TC
  • Python 调用海康机器人工业相机

    一 前期准备 1 python环境搭建 2 安装MVS软件 3 网上博客参考 1 RTSP Runtime Stream Protocol 协议方向 很遗憾 此路不通 因为我们用的 海康机器人工业相机 MV CU060 10GM 这款相机
  • builtin descriptor types

    inspect getattr static obj attr default None Retrieve attributes without triggering dynamic lookup via the descriptor pr