Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Pycon_Africa.pdf

 Pycon_Africa.pdf

Where and How to use Asserts in your Python code!
Best Practices!

Prajjwal Nijhara

August 06, 2020
Tweet

More Decks by Prajjwal Nijhara

Other Decks in Programming

Transcript

  1. Where and How to use Asserts in your python code

    ~Prajjwal Nijhara Twitter: @NijharaPrajjwal Github: @pnijhara Blogs: https://pnijhara.github.io
  2. 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.
  3. 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?
  4. 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.