PLAY PODCASTS
Exploring Duck Typing in Python & Dynamics of Monkey Patching
Episode 196

Exploring Duck Typing in Python & Dynamics of Monkey Patching

The Real Python Podcast · Real Python

March 15, 202450m 46s

Audio is streamed directly from the publisher (dts.podtrac.com) as published in their RSS feed. Play Podcasts does not host this file. Rights-holders can request removal through the copyright & takedown page.

Show Notes

<p>What are the advantages of determining the type of an object by how it behaves? What coding circumstances are not a good fit for duck typing? Christopher Trudeau is back on the show this week, bringing another batch of PyCoder&rsquo;s Weekly articles and projects.</p> <p>Christopher covers a recent Real Python tutorial by Leodanis Pozo Ramos titled Duck Typing in Python: Writing Flexible and Decoupled Code. The tutorial explains the concepts of duck typing within object-oriented programming and its use within Python&rsquo;s built-in tools.</p> <p>We discuss a recent article on monkey patching in Python. This practice of dynamically modifying a class or module&rsquo;s behavior at runtime allows for testing, debugging, and experimentation.</p> <p>We also share several other articles and projects from the Python community, including a news roundup, why names are not the same as objects in Python, using IPython Jupyter magic commands, a discussion about becoming a senior developer, a data exploration challenge, a Python evaluation game, and a terminal UI for regex testing.</p> <p>This week&rsquo;s episode is brought to you by Sentry.</p> <div class="alert alert-primary" role="alert"> <p><strong>Course Spotlight:</strong> <a href="https://realpython.com/courses/pointers-python/">Pointers and Objects in Python</a> </p> <p>In this video course, you&rsquo;ll learn about Python&rsquo;s object model and see why pointers don&rsquo;t really exist in Python. You&rsquo;ll also cover ways to simulate pointers in Python without managing memory.</p> </div> <p>Topics:</p> <ul> <li>00:00:00 &ndash; Introduction</li> <li>00:02:38 &ndash; Listener feedback</li> <li>00:04:02 &ndash; DjangoCon US Call for Proposals</li> <li>00:04:38 &ndash; White House Recommends Use of Python</li> <li>00:05:41 &ndash; JupyterLab 4.1 and Notebook 7.1 Released</li> <li>00:06:05 &ndash; What&rsquo;s in a Name?</li> <li>00:11:52 &ndash; Duck Typing in Python: Writing Flexible and Decoupled Code</li> <li>00:15:07 &ndash; Sponsor: Sentry</li> <li>00:16:11 &ndash; Using IPython Jupyter Magic Commands</li> <li>00:22:31 &ndash; A Guide to Monkey Patching</li> <li>00:25:27 &ndash; Falsehoods Junior Developers Believe About Becoming Senior</li> <li>00:33:01 &ndash; Video Course Spotlight</li> <li>00:34:11 &ndash; Falsehoods continued</li> <li>00:43:43 &ndash; Where in the data?</li> <li>00:46:55 &ndash; the eval game</li> <li>00:48:03 &ndash; rexi: Terminal UI for Regex Testing</li> <li>00:49:43 &ndash; Thanks and goodbye</li> </ul> <p>News:</p> <ul> <li><a href="https://2024.djangocon.us/speaking/">DjangoCon US Call for Proposals</a></li> <li><a href="https://pyfound.blogspot.com/2024/02/white-house-recommends-.html">White House Recommends Use of Python</a></li> <li><a href="https://blog.jupyter.org/jupyterlab-4-1-and-notebook-7-1-are-here-20bfc3c10217">JupyterLab 4.1 and Notebook 7.1 Released</a></li> </ul> <p>Show Links:</p> <ul> <li><a href="https://www.thepythoncodingstack.com/p/whats-in-a-name-python-namespace-objects-names">What&rsquo;s in a Name?</a> &ndash; An article about names in Python, and why they&rsquo;re not the same as objects. The article discusses reference counts and namespaces.</li> <li><a href="https://realpython.com/duck-typing-python/">Duck Typing in Python: Writing Flexible and Decoupled Code</a> &ndash; In this tutorial, you&rsquo;ll learn about duck typing in Python. It&rsquo;s a typing system based on objects&rsquo; behaviors rather than on inheritance. By taking advantage of duck typing, you can create flexible and decoupled sets of Python classes that you can use together or individually.</li> <li><a href="https://towardsdatascience.com/using-ipython-jupyter-magic-commands-to-improve-the-notebook-experience-f2c870cab356">Using IPython Jupyter Magic Commands</a> &ndash; &ldquo;IPython Jupyter Magic commands (e.g. lines in notebook cells starting with % or %%) can decorate a notebook cell, or line, to modify its behavior.&rdquo; This article shows you how to define them and where they can be useful.</li> <li><a href="https://dev.to/karishmashukla/monkeying-around-with-python-a-guide-to-monkey-patching-obc">Monkeying Around With Python: A Guide to Monkey Patching</a> &ndash; Monkey patching is the practice of modifying live code. This article shows you how it&rsquo;s done and why and when to use the practice.</li> </ul> <p>Discussion:</p> <ul> <li><a href="https://vadimkravcenko.com/shorts/falsehoods-junior-developers-believe-about-becoming-senior/">Falsehoods Junior Developers Believe About Becoming Senior</a> &ndash; This opinion piece by Vadim discusses how newer developers perceive what it means to be a senior developer, and how they&rsquo;re often wrong.</li> </ul> <p>Projects:</p> <ul> <li><a href="https://www.whereinthedata.com/">Where in the data?</a></li> <li><a href="https://oskaerik.github.io/theevalgame/">the eval game</a></li> <li><a href="https://github.com/royreznik/rexi">rexi: Terminal UI for Regex Testing</a></li> </ul> <p>Additional Links:</p> <ul> <li><a href="https://realpython.com/pointers-in-python/">Pointers in Python: What&rsquo;s the Point? – Real Python</a></li> <li><a href="https://realpython.com/ipython-interactive-python-shell/">Unlock IPython&rsquo;s Magical Toolbox for Your Coding Journey – Real Python</a></li> <li><a href="https://realpython.com/podcasts/rpp/88/">Episode #88: Discussing Type Hints, Protocols, and Ducks in Python – The Real Python Podcast</a></li> <li><a href="https://www.saul.pw/">saul.pw</a></li> <li><a href="https://www.bluebird.sh/">BlueBird Shell</a></li> </ul> <p>Level up your Python skills with our expert-led courses:</p> <ul> <li><a href="https://realpython.com/courses/python-type-checking/">Python Type Checking</a></li> <li><a href="https://realpython.com/courses/testing-your-code-with-pytest/">Testing Your Code With pytest</a></li> <li><a href="https://realpython.com/courses/pointers-python/">Pointers and Objects in Python</a></li> </ul> <p><a rel="payment" href="https://realpython.com/join">Support the podcast &amp; join our community of Pythonistas</a></p>