Skip to content

Instantly share code, notes, and snippets.

@EpicWink
EpicWink / _dataclass_patch.py
Last active October 4, 2022 12:02
Support non-defaulted after defaulted fields in dataclasses
"""Patch ``dataclasses`` to support optional after required fields.
Fields used in ``__init__`` without defaults are currently not allowed
after fields with defaults, due to the specification in PEP 557. This
patch allows these fields, but makes them required keyword-only
parameters to ``__init__``.
To apply this patch, simply import this module before defining any
dataclasses.
"""
@schipiga
schipiga / uncache.py
Last active June 16, 2021 09:37
python_monkey_patch
import sys
def uncache(exclude):
"""Remove package modules from cache except excluded ones.
On next import they will be reloaded.
Args:
exclude (iter<str>): Sequence of module paths.
"""
pkgs = []