The Real Python Podcast

Practical Python Decorator Uses & Avoiding datetime Pitfalls


Listen Later

What are real-life examples of using Python decorators? How can you harness their power in your code? Christopher Trudeau is back on the show this week, bringing another batch of PyCoder’s Weekly articles and projects.

We discuss a recent article series that digs into Python decorators. The first two articles discuss the basics of constructing decorators. The third part describes how popular Python libraries use decorators with call interception, function registration, and enriching the behavior of a function.

Christopher shares a piece about the common pitfalls of working with the Pythondatetime library. The article considers how current third-party libraries don’t address most of these quirks and offers a potential solution with a new library.

We also share several other articles and projects from the Python community, including a couple of news items, a discussion about the popularity of the Rust language, handling unset values in FastAPI with Pydantic, working with Python’s mini-language for formatting strings, mocking Django queryset functions, and a modern replacement for the Requests library.

This week’s episode is brought to you by Sentry.

Course Spotlight: Python Decorators 101

In this course on Python decorators, you’ll learn what they are and how to create and use them. Decorators provide a simple syntax for calling higher-order functions in Python. By definition, a decorator is a function that takes another function and extends the behavior of the latter function without explicitly modifying it.

Topics:

  • 00:00:00 – Introduction
  • 00:02:53 – Django security releases issued: 5.0.2, 4.2.10, and 3.2.24
  • 00:03:10 – Python 3.12.2 and 3.11.8 are now available
  • 00:03:21 – Introducing PSF Grants Program Office Hours
  • 00:04:19 – Python’s Format Mini-Language for Tidy Strings
  • 00:12:22 – Ten Python datetime Pitfalls
  • 00:18:34 – Sponsor: Sentry
  • 00:19:37 – Real Life Use of Decorators
  • 00:29:18 – Handling Unset Values in FastAPI With Pydantic
  • 00:35:43 – Video Course Spotlight
  • 00:37:06 – The Python Rust-Aissance
  • 00:50:19 – django-mock-queries: Mock Django Queryset Functions
  • 00:53:09 – niquests: Requests but Multiplexed
  • 00:55:55 – Thanks and goodbye
  • News:

    • Django security releases issued: 5.0.2, 4.2.10, and 3.2.24
    • Python 3.12.2 and 3.11.8 are now available
    • Introducing PSF Grants Program Office Hours
    • Show Links:

      • Python’s Format Mini-Language for Tidy Strings – In this tutorial, you’ll learn about Python’s format mini-language. See how to use it for creating working format specifiers and build nicely formatted strings and messages in your code.
      • Ten Python datetime Pitfalls – It’s no secret that the Python datetime library has its quirks. Not only are there probably more than you think, but third-party libraries don’t address most of them! Arie created a new library to explore what a better datetime library could look like.
      • Real Life Use of Decorators – Part 3 in a series on how Python decorators are used. This part covers real-life use cases including call interception, function registration, and behavioral enrichment.
      • Handling Unset Values in FastAPI With Pydantic – When using the HTTP PATCH method only those fields that got changed are updated. Pydantic sets fields not given as arguments as None so there is no way to distinguish between an explicit None value and an unset field. This post explains how you process this scenario.
      • Discussion:

        • The Python Rust-Aissance – Companies like Polars are showing how with Rust, Python developers now have a better, smoother path towards building high-performance libraries.
        • Rye: A Python Developer Experience Vision Continued
        • PyO3: Rust bindings for the Python interpreter
        • Rust in Linux: Where we are and where we’re going next
        • RustPython: OSS CPython Written in Rust
        • granian: Rust HTTP Server for Python Applications
        • Projects:

          • django-mock-queries: Mock Django Queryset Functions for Testing
          • niquests: Requests but Multiplexed
          • Additional Links:

            • Backus–Naur form - Wikipedia
            • ANTLR - (ANother Tool for Language Recognition) A Powerful Parser Generator
            • Xmas Decoration, Part 1 - Bite code!
            • Xmas Decoration, Part 2 - Bite code!
            • Falsehoods programmers believe about time - @noahsussman - Infinite Undo
            • 10 Reasons You Should Quit Your HTTP Client - Ahmed TAHRI - Dev Genius
            • HTTPX - Fully Featured HTTP Client for Python 3
            • Level up your Python skills with our expert-led courses:

              • Using Python's datetime Module
              • Python Decorators 101
              • Python 3's F-Strings: An Improved String Formatting Syntax
              • Support the podcast & join our community of Pythonistas

                ...more
                View all episodesView all episodes
                Download on the App Store

                The Real Python PodcastBy Real Python

                • 4.7
                • 4.7
                • 4.7
                • 4.7
                • 4.7

                4.7

                136 ratings


                More shows like The Real Python Podcast

                View all
                Software Engineering Radio - the podcast for professional software developers by se-radio@computer.org

                Software Engineering Radio - the podcast for professional software developers

                272 Listeners

                The Changelog: Software Development, Open Source by Changelog Media

                The Changelog: Software Development, Open Source

                283 Listeners

                Data Skeptic by Kyle Polich

                Data Skeptic

                481 Listeners

                Talk Python To Me by Michael Kennedy

                Talk Python To Me

                592 Listeners

                Software Engineering Daily by Software Engineering Daily

                Software Engineering Daily

                624 Listeners

                The TWIML AI Podcast (formerly This Week in Machine Learning & Artificial Intelligence) by Sam Charrington

                The TWIML AI Podcast (formerly This Week in Machine Learning & Artificial Intelligence)

                443 Listeners

                Super Data Science: ML & AI Podcast with Jon Krohn by Jon Krohn

                Super Data Science: ML & AI Podcast with Jon Krohn

                296 Listeners

                Python Bytes by Michael Kennedy and Brian Okken

                Python Bytes

                213 Listeners

                Data Engineering Podcast by Tobias Macey

                Data Engineering Podcast

                142 Listeners

                Syntax - Tasty Web Development Treats by Wes Bos & Scott Tolinski - Full Stack JavaScript Web Developers

                Syntax - Tasty Web Development Treats

                982 Listeners

                CoRecursive: Coding Stories by Adam Gordon Bell - Software Developer

                CoRecursive: Coding Stories

                189 Listeners

                DataFramed by DataCamp

                DataFramed

                266 Listeners

                Practical AI by Practical AI LLC

                Practical AI

                189 Listeners

                The Stack Overflow Podcast by The Stack Overflow Podcast

                The Stack Overflow Podcast

                64 Listeners

                Latent Space: The AI Engineer Podcast by swyx + Alessio

                Latent Space: The AI Engineer Podcast

                77 Listeners