Skip to content

Instantly share code, notes, and snippets.

View dvarrazzo's full-sized avatar

Daniele Varrazzo dvarrazzo

View GitHub Profile
@dvarrazzo
dvarrazzo / dicttuple.py
Last active September 7, 2022 16:08
DictCursor for psycopg 3
class DictTuple(tuple):
"""Tuple class with added item getting by name.
"""
def __new__(cls, d):
rv = super().__new__(cls, d.values())
rv._map = d
return rv
def __repr__(self):
return f"{type(self).__qualname__}({self._map!r})"
@dvarrazzo
dvarrazzo / walrusify.py
Last active March 28, 2025 11:25
A script to convert assignments followed by ifs with a walrus operator
#!/usr/bin/env python
"""Convert a codebase to using the walrus operator.
Hint: in order to explore the AST of a module you can run:
python -m ast path/to/module.py
"""
from __future__ import annotations