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
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
コマンドとリード間の連携に対する脅威分析フレームワーク
pandayumi
1
450
AIによる開発の民主化を支える コンテキスト管理のこれまでとこれから
mulyu
3
190
0→1 フロントエンド開発 Tips🚀 #レバテックMeetup
bengo4com
0
560
今こそ知るべき耐量子計算機暗号(PQC)入門 / PQC: What You Need to Know Now
mackey0225
3
370
Grafana:建立系統全知視角的捷徑
blueswen
0
330
AI Schema Enrichment for your Oracle AI Database
thatjeffsmith
0
270
ThorVG Viewer In VS Code
nors
0
770
20260127_試行錯誤の結晶を1冊に。著者が解説 先輩データサイエンティストからの指南書 / author's_commentary_ds_instructions_guide
nash_efp
1
940
生成AIを使ったコードレビューで定性的に品質カバー
chiilog
1
260
CSC307 Lecture 08
javiergs
PRO
0
670
AIによる高速開発をどう制御するか? ガードレール設置で開発速度と品質を両立させたチームの事例
tonkotsuboy_com
7
2.2k
AtCoder Conference 2025
shindannin
0
1.1k
Featured
See All Featured
Breaking role norms: Why Content Design is so much more than writing copy - Taylor Woolridge
uxyall
0
160
Paper Plane
katiecoart
PRO
0
46k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.7k
GitHub's CSS Performance
jonrohan
1032
470k
Agile that works and the tools we love
rasmusluckow
331
21k
The Curious Case for Waylosing
cassininazir
0
230
職位にかかわらず全員がリーダーシップを発揮するチーム作り / Building a team where everyone can demonstrate leadership regardless of position
madoxten
57
50k
How Fast Is Fast Enough? [PerfNow 2025]
tammyeverts
3
450
We Are The Robots
honzajavorek
0
160
DevOps and Value Stream Thinking: Enabling flow, efficiency and business value
helenjbeal
1
92
Noah Learner - AI + Me: how we built a GSC Bulk Export data pipeline
techseoconnect
PRO
0
100
Believing is Seeing
oripsolob
1
53
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