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
110
0
Share
Lightning Talk "Opening CPython Built-in Classes" (Europython)
Jesús Espino
July 24, 2015
More Decks by Jesús Espino
See All by Jesús Espino
Brewed for Speed: How Go’s Green Tea GC Works
jespino
0
26
Deep dive into the select statment
jespino
0
32
Exploring a complex codebase with AI
jespino
0
24
Explorando el Open Source con IA
jespino
0
20
Deep dive into a go binary
jespino
1
230
Deep dive in a SQL query (PgIbz)
jespino
2
170
Understanding the go runtime
jespino
1
190
Tests end-to-end en entornos complejos con testcontainers
jespino
0
58
Dissecting Slices, Maps and Channels in Go
jespino
0
93
Other Decks in Programming
See All in Programming
ふつうのFeature Flag実践入門
irof
5
2.2k
プラグインで拡張される Context をtype-safe にする難しさと設計判断
kazupon
2
300
Talking to terminals (and how they talk back) (KotlinConf 2026)
jakewharton
PRO
1
120
LLM Plugin for Node-REDの利用方法と開発について
404background
0
110
Why Laravel apps break—Mastering the fundamentals to keep them maintainable
kentaroutakeda
1
200
AlarmKitで明後日起きれるアラームアプリを作る
trickart
0
150
Agent Skills を社内で育てる仕組み作り
jackchuka
1
2.4k
新規プロダクトを高速で生み出すハーネスエンジニアリング
seanchas116
3
270
開発体験を左右するライブラリの API 設計 - GraphQL スキーマ構築ライブラリから考える #tskaigi
izumin5210
2
520
要はバランスからの卒業 #yumemi_grow
kajitack
0
190
過去のレビュー知見をSkillsで資産化した話
pkshadeck
PRO
1
2.3k
AI Agent と正しく分析するための環境作り
yoshyum
2
600
Featured
See All Featured
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
508
140k
The Spectacular Lies of Maps
axbom
PRO
1
760
DevOps and Value Stream Thinking: Enabling flow, efficiency and business value
helenjbeal
1
200
It's Worth the Effort
3n
188
29k
How To Speak Unicorn (iThemes Webinar)
marktimemedia
1
460
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
46
2.8k
技術選定の審美眼(2025年版) / Understanding the Spiral of Technologies 2025 edition
twada
PRO
118
120k
Digital Projects Gone Horribly Wrong (And the UX Pros Who Still Save the Day) - Dean Schuster
uxyall
0
1.5k
Utilizing Notion as your number one productivity tool
mfonobong
4
310
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
333
22k
Highjacked: Video Game Concept Design
rkendrick25
PRO
1
360
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
231
23k
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