Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Lightning Talk "Opening CPython Built-in Classe...
Search
Jesús Espino
July 24, 2015
Programming
120
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Lightning Talk "Opening CPython Built-in Classes" (Europython)
Jesús Espino
July 24, 2015
Transcript
14 slides
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
More Decks by Jesús Espino
See All by Jesús Espino
How to create a database optimized for petabytes of logs and wide events
jespino
0
26
The life of a metric
jespino
0
34
Deep dive into the select statement (GopherCon UK)
jespino
0
230
Brewed for Speed: How Go’s Green Tea GC Works
jespino
0
74
Deep dive into the select statment
jespino
0
70
Exploring a complex codebase with AI
jespino
0
76
Explorando el Open Source con IA
jespino
0
47
Deep dive into a go binary
jespino
1
320
Deep dive in a SQL query (PgIbz)
jespino
2
220
Other Decks in Programming
See All in Programming
protojson における文字化けの扱い
kazuki1023
0
430
Distance field of Julia set
kinakomoti321
0
320
Spec-Driven Development - Why Vaadin Is the Perfect Fit
simas
PRO
0
250
Coding with AI: How to trust the storyteller (AWS Community Day Adria, Ljubljana 2026)
slobodan
0
150
Snowflake Openflow Connector利用の勘所 / 20261024developersio2026tokyo-snowflake-openflow
kasacchiful
PRO
0
340
あなたの await、OS まで届いてる? strace で覗く JavaScript の非同期
hasutosasaki
1
2.4k
小さなアプリを作って公開するまで
onozaty
0
180
조합이폭발하는디자인시스템이걸눈으로도테스트하라고요
giljongyu
0
750
Kotlin Fest 2026: Kotlin コンパイラに Contribute してみよう! - Kotlin/Wasm で深い再帰を書けるようにした話
ternbusty
1
110
React Native経験者が Flutterを30⽇間触って驚いたこと
3saito
0
190
Spec-driven Development with AI
simas
PRO
0
2.3k
AIが実装を担う時代の「技術設計」と「チームマネジメント」
kamina_zzz
2
270
Featured
See All Featured
How People are Using Generative and Agentic AI to Supercharge Their Products, Projects, Services and Value Streams Today
helenjbeal
2
400
We Have a Design System, Now What?
morganepeng
55
8.4k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
162
16k
How to train your dragon (web standard)
notwaldorf
96
6.9k
Typedesign – Prime Four
hannesfritz
42
3.2k
Jamie Indigo - Trashchat’s Guide to Black Boxes: Technical SEO Tactics for LLMs
techseoconnect
PRO
0
750
Highjacked: Video Game Concept Design
rkendrick25
PRO
2
570
Building a A Zero-Code AI SEO Workflow
portentint
PRO
0
830
Primal Persuasion: How to Engage the Brain for Learning That Lasts
tmiket
0
520
Noah Learner - AI + Me: how we built a GSC Bulk Export data pipeline
techseoconnect
PRO
0
490
Technical Leadership for Architectural Decision Making
baasie
4
650
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
11
1.1k