Brought to you by Michael and Brian - take a Talk Python course or get Brian's pytest book

#291: Wait, you have how many licenses?!?

Published Wed, Jul 6, 2022, recorded Wed, Jul 6, 2022
Watch this episode on YouTube
Play on YouTube
Watch the live stream replay

About the show

Sponsored by us! Support our work through:

Michael #1: Python License tracker

  • by Tom Nijhof/Nyhof
  • Every package depends on other package with sometimes different licenses.
  • Tom made a tool to find out what licenses you all need for a project:
  • PyTest alone needs 4 different licenses for itself and its dependencies.
  • Tensorflow is even worst

Brian #2: undataclass

  • Trey Hunner
  • As a teaching aid, and to show how much dataclasses do for you, this is a module and an application that converts dataclasses to normal classes, and fills in all of the dunder methods you need.
  • Example in app:

    from dataclasses import dataclass
        class Point:
            x: float
            y: float
            z: float
  • Converts to

    class Point:
            __match_args__ = ('x', 'y', 'z')
            def __init__(self, x: float, y: float, z: float) -> None:
                self.x = x
                self.y = y
                self.z = z
            def __repr__(self):
                cls = type(self).__name__
                return f'{cls}(x={self.x!r}, y={self.y!r}, z={self.z!r})'
            def __eq__(self, other):
                if not isinstance(other, Point):
                    return NotImplemented
                return (self.x, self.y, self.z) == (other.x, other.y, other.z)
  • Note on NotImplemented:

    • It just means, “I don’t know how to compare this”, and Python will try __eq__ on the other object. If that also raises NotImplemented, a False is returned.
  • The default is the above with @dataclass(frozen=True, slots=True) and adds the methods:
    • fronzen=True gives you implementations of __hash__, __setattr__, __delattr__, __getstate__, __setstate__,
      • Essentially raises exception if you try to change the contents, and makes your objects hashable.
    • slots=True adds the line: __slots__ = (``'``x', '``y``'``, '``z``'``).
      • This disallows adding new attributes to objects at runtime. See Python docs
  • Trey wrote two posts about it:
  • Turns out, this is a cool example for AST and structural pattern matching.
  • Notes from the “how I made..” article:
  • "I used some tricks I don't usually get to use in Python. I used:
  1. Many very hairy **match**-**case** blocks which replaced even hairier if-elif blocks
  2. A sentinel object to keep track of a location that needed replacing
  3. Python's **textwrap.dedent** utility, which I feel should be more widely known & used
  4. slice assignment to inject one list into another
  5. The ast module's unparse function to convert an abstract syntax tree into Python code”

Michael #3: Qutebrowser

  • via Martin Borus
  • Qutebrowser is a keyboard-focused browser with a minimal GUI."
  • It's Python powered
  • Whats more important - doesn't force you to use it's Vim-based shortcuts, the mouse
  • still works. But you usually don't need it: Because on any page, a keypress on the "f" key will show, you every clickable think and a letter combination to enter to click this.

Brian #4: asyncio and web applications

  • A collection of articles
  • Quart is now a Pallets project
    • P G Jones, maintainer of Quart and Hypercorn
    • “Quart, an ASGI re-implementation of the Flask API has joined the Pallets organization. This means that future development will be under the Pallets governance by the Pallets maintainers.
    • Our long term aim is to merge Quart and Flask to bring ASGI support directly to Flask.
    • “When to use Quart?”
      • “Quart is an ASGI framework utilising async IO throughout, whereas Flask is a WSGI framework utilising sync IO. It is therefore best to use Quart if you intend to use async IO (i.e. async/await libraries) and Flask if not. Don't worry if you choose the 'wrong' framework though, as Quart supports sync IO and Flask supports async IO, although less efficiently.”
  • Using async and await, from Flask docs
    • Flask has some support of async/await since Flask 2.0
    • But it’s still a WSGI application.
    • “Deciding whether you should use Flask, Quart, or something else is ultimately up to understanding the specific needs of your project.”
  • Should You Use AsyncIO for Your Next Python Web Application?
    • Steven Pate
    • A cool “brief history of Python web server interfaces”
    • Discussion of the Python servers and frameworks for both WSGI and ASGI
    • Recommendation: Do you need async? “… most people don’t. WSGI servers and frameworks are usually performant enough.”



Joke: Understanding JavaScript

Joke: Where do you see yourself in 5 years?

Want to go deeper? Check our projects