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
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
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
QAフローを最適化し、品質水準を満たしながらリリースまでの期間を最短化する #RSGT2026
shibayu36
2
4.3k
360° Signals in Angular: Signal Forms with SignalStore & Resources @ngLondon 01/2026
manfredsteyer
PRO
0
120
AI & Enginnering
codelynx
0
110
責任感のあるCloudWatchアラームを設計しよう
akihisaikeda
3
170
余白を設計しフロントエンド開発を 加速させる
tsukuha
7
2.1k
dchart: charts from deck markup
ajstarks
3
990
CSC307 Lecture 06
javiergs
PRO
0
680
今こそ知るべき耐量子計算機暗号(PQC)入門 / PQC: What You Need to Know Now
mackey0225
3
370
CSC307 Lecture 09
javiergs
PRO
1
830
AIによる開発の民主化を支える コンテキスト管理のこれまでとこれから
mulyu
3
160
高速開発のためのコード整理術
sutetotanuki
1
390
Smart Handoff/Pickup ガイド - Claude Code セッション管理
yukiigarashi
0
130
Featured
See All Featured
New Earth Scene 8
popppiees
1
1.5k
Designing for Timeless Needs
cassininazir
0
130
Believing is Seeing
oripsolob
1
53
職位にかかわらず全員がリーダーシップを発揮するチーム作り / Building a team where everyone can demonstrate leadership regardless of position
madoxten
57
50k
Why Our Code Smells
bkeepers
PRO
340
58k
The SEO Collaboration Effect
kristinabergwall1
0
350
How to Grow Your eCommerce with AI & Automation
katarinadahlin
PRO
0
110
Reflections from 52 weeks, 52 projects
jeffersonlam
356
21k
Chasing Engaging Ingredients in Design
codingconduct
0
110
Testing 201, or: Great Expectations
jmmastey
46
8k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
38
2.7k
The Straight Up "How To Draw Better" Workshop
denniskardys
239
140k
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