5 刘知杭 静态类型的Python## 静态类型的Python PYTHON 30th Lyzh(刘知杭) ## 目录 CONTENTS ➤ 有关类型的概念 使用mypy对Python源代码进行静态分析 代数数据类型 拓展知识 ## 关于类型的一些基本概念 有类型不等于有类型系统 PYTHON 30th 动态语言类型化的必要性 ## 不久前的一个案例 ☀️ ☀️ ☁️ rl = filter(lambda x: HttpResponse(json.dumps(rl), content_type='application/json') ## 类型的概念 CPython定义了PyObject这个结构体作为对象头。 CPython中的类型,是指在对象头中指向类型元信息的指针。 ## ●●● // cpython/include/object.h #define PyObject_HEAD PyObject CPython有类型,但CPython没有类型系统。这就是CsPython中诸多问题的由来。 ## 类型系统是什么? 类型系统(type system)是一种编译期(Compile-time)的类型推导检查规则。 类型系统(type system)的基本目标是防止程序在运行时发生类型错误。当且仅当语言运行时不存在任何形式的类型错误,那么它就是sound的。soundness是类型系统研究的重要目标。0 码力 | 42 页 | 6.87 MB | 2 年前3
TypeScript 类型系统## TypeScript 类型系统 分享人:陈文岗 学校:中国科学院大学 2021年1月21日 ## 关于TypeScript TypeScript是微软推出的JavaScript静态类型版本,它是JavaScript的超集,可以编译为纯粹的JavaScript TypeScript How Does TypeScript Work? TypeScript file.ts JavaScript jpg) ## TypeScript 基础类型 // 数字类型 let num: number; num = 123; // 布尔类型 let flag: boolean; flag = false; // 字符串类型 let str: string; str = 'Hello World'; ## TypeScript 高级类型 // 数组类型 let arr: number]; arr 'chenwengang', age: 23 }; // 函数类型/函数签名 type Callback = () => void; let cb:Callback = () => { console.log('callback'); }; ## TypeScript 高级类型 // 交叉类型 type User1 = { name: string;0 码力 | 25 页 | 1.27 MB | 2 年前3
3 Thautwarm 解放python的表达力 性能和安全性 语法和语义扩展 JIT 静态检查解放Python的 表达力,性能和安全性 Thautwarm 目录 CONTENTS >> 语法和语义扩展 >> JIT >> 静态类型  ## 语法和语义扩展 演示一小部分: and: 满足多个解构规则的组合模式 or: 满足其中一个解构规则的组合模式 A(a, ...): 调用A.__match__进行模式匹配 isinstance(type): 检查类型的pattern (a, *b, c): 匹配tuple [a, *b, c]: 匹配列表 ## Pattern-Matching benchmark.py ●●● # In [1]: 所有参数的typeid组成了一个tuple, 这个tuple被添加到一个叫jit_call_recorder的尾部。 jit_call_recorder根据调用记录唤醒jit编译器,根据用户可自定义的规则选择足够热的几个参数类型组进行编译,生成jit函数的几个method。 同时,每次编译会根据已有的所有methods,生成一个新的method查找函数。 ## JIT机制:简单又实用,就写了一天  但一般意义上的指针分析是NP-hard问题 智能指针可行,但作为运行时方案,效率低 ■ Rust在语法设计中引入所有权机制,简化指针分析问题 ## Rust所有权模型 ☐ Rust为了提升可用性所做的妥协 智能指针(性能损失) ☑ 允许使用裸指针(unsafe模式) next prev next prev next prev • 逃逸编译器的借用检查 => 指针别名 struct List{ val: u64, prev: Option>>, next: Option 0 码力 | 28 页 | 1.55 MB | 2 年前3
Mypy 1.10.0+dev Documentationtype Any are present within your codebase. ## --cobertura-xml-report DIR Causes mypy to generate a C键类型 XML type checking coverage report. To generate this report, you must either manually install the lxml are present within your codebase. cobertura_xml_report Type: string Causes mypy to generate a C键类型 XML type checking coverage report. To generate this report, you must either manually install the lxml0 码力 | 318 页 | 270.84 KB | 2 年前3
Mypy 1.8.0 Documentationtype Any are present within your codebase. ## --cobertura-xml-report DIR Causes mypy to generate a C键类型 XML type checking coverage report. To generate this report, you must either manually install the lxml are present within your codebase. ## cobertura_xml_report Type string Causes mypy to generate a C键类型 XML type checking coverage report. To generate this report, you must either manually install the lxml0 码力 | 234 页 | 902.89 KB | 2 年前3
基本数据类型## PyTorch ## 基本数据类型 主讲人:龙良曲 ## All is about Tensor |python|PyTorch| |---|---| |Int|IntTensor of size()| |float|FloatTensor of size()| |Int array|IntTensor of size \[d1, d2, ...]| |Float array|FloatTensor0 码力 | 16 页 | 1.09 MB | 2 年前3
共 1000 条
- 1
- 2
- 3
- 4
- 5
- 6
- 100













