Chris Padilla/Blog

My passion project! Posts spanning music, art, software, books, and more
You can follow by RSS! (What's RSS?) Full archive here.

    Parkway

    🌳

    Getting ready to move neighborhoods next month. The current place is just walking distance from a beautiful trail. So I'm savoring it while we're still here!


    All the Things You Are Chord Melody

    Listen on Youtube

    My first swing at chord melody! Love this tune even more on guitar.


    Night Lake

    🌙

    The veil is thin. 👻

    Squeaked in one Inktober drawing this year! Very much directly inspired by the energetic ink work of Violaine Briat's Lil' Dee.


    TypedDicts in Python

    So much of JavaScript/TypeScript is massaging data returned from an endpoint through JSON. TypeScript has the lovely ability to type the objects and their properties that come through.

    While Python is not as strongly typed as TypeScript, we have this benefit built in to the type hinting system.

    It's easier shown than explained:

    from typing import Union, TypedDict
    from datetime import datetime
    
    
    class Concert(TypedDict):
        """
        Type Dict for concert dictionaries.
        """
    
        id: str
        price: int
        artist: str
        show_time: Union[str, datetime]

    All pretty straightforward. We're instantiating a class, inheriting from the TypedDict base class. Then we set our expected properties as values on that class.

    It's ideal to store a class like this in it's own types directory in your project.

    A couple of nice ways to use this:

    First, you can use this in your methods where you are expecting to receive this dictionary as an argument:

    def get_concert_ticket_details(
            self, concert: UnitDict = None
        ) -> tuple(list[str], set[str]):
        // Do work

    You can also directly create a dictionary from this class through instantiation.

    concert = Concert({
        "id": "28",
        "price": 50,
        "artist": "Prince",
        "show_time": show_time
    })

    The benefit of both is, of course, the suggestion in your editor letting you know that a property does not match the expected shape.

    More details on Python typing in this previous post. Thorough details available in the official docs.


    Sonny Rollins – Oleo

    Listen on Youtube

    Today I learned that this jazz standard is named after margarine. Yum!