Finding the Best Posts

See my top posts page for a selection of my best posts. Or search the site with Duck Duck Go:


Recent Posts

Truncating my blog posts with Python’s HTMLParser

Not a bowl of beautiful soup.

I recently converted this blog to Pelican, a Python powered static site generator. On the way I added a few customizations. One customization is a Jinja template filter to truncate a post’s HTML as a summary, using Python’s HTMLParser class. Here’s how I wrote it.

Read more...

How to Fix Pip “Yanked Version” Warnings

Are you yanking my chain?

Sometimes pip install will flag a warning saying “The candidate selected for download or install is a yanked version”. For example, if we install attrs version 21.1.0:

Read more...

Does Python support semicolons?

Are semicolons just for dragons?

Many languages follow the syntax of C, and use semicolons to indicate the end of a statement. For example, in JavaScript:

Read more...

Why does Python log a warning for “invalid decimal literal”?

Where did this warning come from?

Take this function:

Read more...

Introducing django-upgrade, a tool for upgrading your Django projects

Giddy-up, we’re going to the future!

Django deprecates a small list of features with every feature release, requiring us to update our projects, which can be monotonous. Today I’m announcing a new tool I’ve created, django-upgrade, that automates some of this drudgery for us all.

Read more...

I converted my Lambda@Edge Function to CloudFront Functions

How to function in the clouds.

When Lambda@Edge first came out, I added it to my blog’s CloudFront distribution in order to add security headers. Then, when Lambda@Edge added Python support, I converted my function from JavaScript to Python.

Read more...

Three Cheers for blacken-docs

Blacken all ye docs.

Black is the de facto standard code formatter for Python, and these days I use it on all my projects. blacken-docs is a tool that also allows you to apply Black to code samples in your docs. I recently rolled it out on my projects to great effect.

Read more...

This Blog Is Now a Pythonic Pelican-Powered Publication

The pelican takes flight...

I started this blog in 2014 using the popular Jekyll. Whilst it served me well, I’ve wanted to migrate to a Python-based tool for a while now, for a few reasons:

Read more...

Python Type Hints - Use Cases for the types Module

Some kind of tool for working with types.

Writing type hints gives us some familiarity with the typing module. But Python also includes the similarly-named types module, which can also come in handy. Let’s look at the history of these two modules, some use cases of types, and one way in which it’s not so useful.

Read more...

Python Type Hints - How to Work with Regular Expressions

Searching again for a needle in a haystack.

Python’s re module lets us search both str and bytes strings with regular expressions (regexes). Our type checker can ensure we call re functions with the correct types, thanks to some parametrized classes.

Read more...