Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Lightning Talk "Opening CPython Built-in Classe...
Search
Jesús Espino
July 24, 2015
Programming
0
110
Lightning Talk "Opening CPython Built-in Classes" (Europython)
Jesús Espino
July 24, 2015
Tweet
Share
More Decks by Jesús Espino
See All by Jesús Espino
Deep dive into the select statment
jespino
0
20
Exploring a complex codebase with AI
jespino
0
11
Explorando el Open Source con IA
jespino
0
10
Deep dive into a go binary
jespino
1
190
Deep dive in a SQL query (PgIbz)
jespino
2
140
Understanding the go runtime
jespino
1
170
Tests end-to-end en entornos complejos con testcontainers
jespino
0
43
Dissecting Slices, Maps and Channels in Go
jespino
0
76
Understanding the memory model of 5 languages
jespino
0
170
Other Decks in Programming
See All in Programming
2年のAppleウォレットパス開発の振り返り
muno92
PRO
0
180
ゆくKotlin くるRust
exoego
1
210
Giselleで作るAI QAアシスタント 〜 Pull Requestレビューに継続的QAを
codenote
0
340
Patterns of Patterns
denyspoltorak
0
900
Implementation Patterns
denyspoltorak
0
210
SQL Server 2025 LT
odashinsuke
0
180
IFSによる形状設計/デモシーンの魅力 @ 慶應大学SFC
gam0022
0
210
クラウドに依存しないS3を使った開発術
simesaba80
0
230
從冷知識到漏洞,你不懂的 Web,駭客懂 - Huli @ WebConf Taiwan 2025
aszx87410
2
3.4k
Honoを使ったリモートMCPサーバでAIツールとの連携を加速させる!
tosuri13
1
140
今こそ知るべき耐量子計算機暗号(PQC)入門 / PQC: What You Need to Know Now
mackey0225
3
320
AI前提で考えるiOSアプリのモダナイズ設計
yuukiw00w
0
210
Featured
See All Featured
For a Future-Friendly Web
brad_frost
180
10k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
666
130k
How to Ace a Technical Interview
jacobian
281
24k
Conquering PDFs: document understanding beyond plain text
inesmontani
PRO
4
2.2k
The agentic SEO stack - context over prompts
schlessera
0
590
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
17k
How to Grow Your eCommerce with AI & Automation
katarinadahlin
PRO
0
91
WCS-LA-2024
lcolladotor
0
420
StorybookのUI Testing Handbookを読んだ
zakiyama
31
6.5k
Exploring the relationship between traditional SERPs and Gen AI search
raygrieselhuber
PRO
2
3.5k
SEO in 2025: How to Prepare for the Future of Search
ipullrank
3
3.3k
Navigating the Design Leadership Dip - Product Design Week Design Leaders+ Conference 2024
apolaine
0
150
Transcript
Opening CPython Built-in Classes JESUS ESPINO GARCIA, DEVELOPER #007000
What’s the problem?
Closed built-in classes >>> int.x = 3 Traceback (most recent
call last): File "<stdin>", line 1, in <module> TypeError: can't set attributes of built-in/extension type 'int'
The solution
Master Key >>> import masterkey >>> masterkey.open_class(int) >>> int.x =
3 >>> (10).x 3
Application
Fix broken float comparisons >>> assert 1.3332 == 1.3333 Traceback
(most recent call last): File "<stdin>", line 1, in <module> AssertionError >>> float.__eq__ = lambda self, other: abs(abs(self) - abs(other)) < 0.1 >>> 1.3332 == 1.3333 True >>> 1.7 == 1.1 False
Add sense to the << operator >>> 5 << 1
10 >>> 5 << 2 20 >>> int.__lshift__ = lambda self, other: self * (10 ** other) >>> 5 << 1 50 >>> 5 << 2 500
More semantic bool __repr__ >>> True == True True >>>
True == False False >>> bool.__repr__ = lambda x: ‘Yes’ if True else ‘No’ >>> True == True Yes >>> True == False No
Be more rubyist >>> from masterkey import rubint >>> (3).times(print)
0 1 2 >>> (3).upto(5, print) 4 5 >>> (3).downto(1, print) 2 1
Close your own classes >>> class MyClass: ... pass >>>
masterkey.close_class(MyClass) >>> MyClass.x = 3 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: can't set attributes of built-in/extension type 'MyClass'
Of course, this is a joke
The black magic import ctypes from operator import xor longsize
= ctypes.sizeof(ctypes.c_long) def open_class(klass): int_flags = ctypes.c_long.from_address(id(klass) + longsize * 21) int_flags.value |= 1 << 9 def close_class(klass): int_flags = ctypes.c_long.from_address(id(klass) + longsize * 21) int_flags.value = xor(int_flags.value, 1 << 9)
The code http://www.github.com/jespino/python-master-key