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
Pycon_Africa.pdf
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Prajjwal Nijhara
August 06, 2020
Programming
95
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Pycon_Africa.pdf
Where and How to use Asserts in your Python code!
Best Practices!
Prajjwal Nijhara
August 06, 2020
More Decks by Prajjwal Nijhara
See All by Prajjwal Nijhara
Raft_Consensus_Algorithm_Prajjwal.pdf
pnijhara
0
30
Setting up your Python environment for ML
pnijhara
0
50
Other Decks in Programming
See All in Programming
Flow は今どうなっているか
mizdra
PRO
0
890
typoなんかねぇよ
raspython3
0
660
Can LLMs Replicate 4 Years of Compose Migration? Exploring the boundaries of automation with 279 XML files from a real product
makun
0
130
まずはプロンプトガイドを読もう、話はそれからだ
kiakiraki
1
250
FDEとは、何者なのか?
masapyon1212
0
130
Foundry Localでエージェント開発
seosoft
0
120
レビュー履歴をAIに食わせて、 Compose移行を加速するs
shihochan
0
260
新人はどこまで自力でやり、どこからAIに頼るべきか/エンジニア育成に向き合う_先輩たちの悩みと知見共有会
toppan_digital_dev
1
550
Discordを用いたラボオートメーション関連情報収集の自動化
noguhiro2002
0
490
From 6 People Classroom Meetup to 100 People Regional Conference / FOSS4G Hiroshima 2026
furukawayasuto
0
100
ハーネス設計入門 〜プロンプト、コンテキストの次〜
kinopeee
53
35k
コンパウンドプロダクト開発のためのローカルプロセスマネージャー再発明 #layerxgo
izumin5210
0
620
Featured
See All Featured
A brief & incomplete history of UX Design for the World Wide Web: 1989–2019
jct
2
490
DevOps and Value Stream Thinking: Enabling flow, efficiency and business value
helenjbeal
1
380
Site-Speed That Sticks
csswizardry
13
1.5k
Imperfection Machines: The Place of Print at Facebook
scottboms
270
14k
Writing Fast Ruby
sferik
630
63k
The untapped power of vector embeddings
frankvandijk
2
1.9k
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
11
1k
How Fast Is Fast Enough? [PerfNow 2025]
tammyeverts
3
870
XXLCSS - How to scale CSS and keep your sanity
sugarenia
249
1.3M
Prompt Engineering for Job Search
mfonobong
0
430
New Earth Scene 8
popppiees
3
2.5k
Hiding What from Whom? A Critical Review of the History of Programming languages for Music
tomoyanonymous
3
1.2k
Transcript
Where and How to use Asserts in your python code
~Prajjwal Nijhara Twitter: @NijharaPrajjwal Github: @pnijhara Blogs: https://pnijhara.github.io
The assert statement exists in almost every programming language. It
helps detect problems early in your program, where the cause is clear, rather than later as a side-effect of some other operation.
How Asserts work?
Assert Equivalent to
Example
Output:
Then where is the problem?
Python’s -O (optimize) flag
During this, these basic optimizations are done: • All the
assert statements are removed • All docstrings are removed (when -OO is selected) • Value of the __debug__ built-in variable is set to False What goes down?
Let us test the above code with -O flag
What can go wrong? If assert statements are used for
user-facing validation in production code, the block won’t be executed at all — potentially opening up a security vulnerability.
Look how syrusakbary validates mail
Fix! It is recommended to use Asserts only in tests.
Issue in Mopidy
Fix!
~Prajjwal Nijhara Twitter: @NijharaPrajjwal Github: @pnijhara Blogs: https://pnijhara.github.io Thank You!
References - https://discuss.deepsource.io/t/using-assert-outside-tests/79 - https://deepsource.io/blog/python-common-mistakes/ - https://github.com/syrusakbary/validate_email/blob/master/validate_email.py#L127 - https://github.com/mopidy/mopidy/issues/1903 -
https://github.com/mopidy/mopidy/pull/1904/files - https://deepsource.io