-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtalk-notes
114 lines (100 loc) · 2.97 KB
/
talk-notes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
Global state
- Recursion
- God objects / Singletons
- Per-thread state: Flask's request
- Proxying
- Recursion (internal redirects) - stack
- Garbage Collection
- Databases
- Modules
- Namespaces
- codecs.lookup
- Module state
- csv.field_size_limit
- Classes
- Monkeypatching
- Dependency injection
- Filesystem
- Sandboxed apps / Portals
- Interpreter
- Plugins for other SW
Magic
- Loops
- Classes
- Decorators
- Descriptors
- Metaclasses
- PEP 487: init_subclass
- Call Stack Inspection
- Import hooks
- Global (or per-thread) state
Import deep dive
- The Basics: File-based importing
- Import statement
- __import__ function
- importlib
- imp
- Finding
- PEP 235 (Import on Case-Insensitive Platforms)
- Code
- PEP 263 (Defining Python Source Code Encodings)
- PEP 3120 (Using UTF-8 as the default source encoding)
- Cache
- PEP 3147 (PYC Repository Directories)
- Filename tags
- sys.path
- Reloading modules
- What reload() does
- IPython's %autoreload
- Reload in Web frameworks
- Packages
- Absolute vs. relative imports
- PEP 328 (Imports: Multi-Line and Absolute/Relative)
- Import loops
- Namespace packages
- Classic: __path__ manipulation
- Now: PEP 420 (Implicit Namespace Packages)
- The machinery
- PEP 302 (New Import Hooks)
- PEP 451 (A ModuleSpec Type for the Import System)
- The Meta Path
- Finders
- ModuleSpec
- Loaders
- Importers (Finder+Loader combined)
- Built-in Modules
- Frozen Modules
- Module Matrix (compiled-in vs external ; Python vs C)
- Extension modules
- Extension modules
- Module cache
- ABI tags
- PEP 3149 (ABI version tagged .so files)
- PEP 489 (Redesigning extension module loading)
- Custom finders
- Zip imports (and zipapp)
- PEP 441 (Improving Python ZIP Application Support)
- Cython's pyximport
- importlib.abc
- InspectLoader
- URL imports
- (Git imports)
- Other Loader Functionality
- get_data() (ResourceLoader)
- get_code() (InspectLoader)
- The -m switch and runpy
- How the __main__ module is special
- PEP 338 (Executing modules as scripts)
Whatever you need to do with Python, you can probably import a library for it.
But what exactly happens when you use that import statement?
How does a source file that you've installed or written become a Python module
object, providing methods or classes for you to play with?
While the import mechanism is relatively well-documented in the reference and
dozens of PEPs, sometimes even Python veterans are caught by surprise.
And some details are little-known: did you know you can import from zip
archives? Write CPython modules in C, or a dialect of Lisp?
Or even import from URLs (which might not be a good idea)?
This talk explains exactly what can happen when you use the import statement –
from the mundane machinery of searching PYTHONPATH through subtle details
of packages and import loops, to deep internals of custom importers and
C extension loading.