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
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
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
Brewed for Speed: How Go’s Green Tea GC Works
jespino
0
10
Deep dive into the select statment
jespino
0
22
Exploring a complex codebase with AI
jespino
0
12
Explorando el Open Source con IA
jespino
0
11
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
50
Dissecting Slices, Maps and Channels in Go
jespino
0
79
Other Decks in Programming
See All in Programming
HTTPプロトコル正しく理解していますか? 〜かわいい猫と共に学ぼう。ฅ^•ω•^ฅ ニャ〜
hekuchan
2
680
メルカリのリーダビリティチームが取り組む、AI時代のスケーラブルな品質文化
cloverrose
2
510
MUSUBIXとは
nahisaho
0
130
AI時代の認知負荷との向き合い方
optfit
0
150
MDN Web Docs に日本語翻訳でコントリビュート
ohmori_yusuke
0
650
CSC307 Lecture 07
javiergs
PRO
0
550
AIによる高速開発をどう制御するか? ガードレール設置で開発速度と品質を両立させたチームの事例
tonkotsuboy_com
7
2.2k
Rust 製のコードエディタ “Zed” を使ってみた
nearme_tech
PRO
0
160
IFSによる形状設計/デモシーンの魅力 @ 慶應大学SFC
gam0022
1
300
AI前提で考えるiOSアプリのモダナイズ設計
yuukiw00w
0
220
Vibe Coding - AI 驅動的軟體開發
mickyp100
0
170
Amazon Bedrockを活用したRAGの品質管理パイプライン構築
tosuri13
4
270
Featured
See All Featured
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
31
3.1k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
287
14k
Navigating Algorithm Shifts & AI Overviews - #SMXNext
aleyda
0
1.1k
Jess Joyce - The Pitfalls of Following Frameworks
techseoconnect
PRO
1
64
The State of eCommerce SEO: How to Win in Today's Products SERPs - #SEOweek
aleyda
2
9.5k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
26
3.3k
Money Talks: Using Revenue to Get Sh*t Done
nikkihalliwell
0
150
The Spectacular Lies of Maps
axbom
PRO
1
520
The innovator’s Mindset - Leading Through an Era of Exponential Change - McGill University 2025
jdejongh
PRO
1
89
Leo the Paperboy
mayatellez
4
1.4k
Darren the Foodie - Storyboard
khoart
PRO
2
2.4k
The Hidden Cost of Media on the Web [PixelPalooza 2025]
tammyeverts
2
180
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