Skip to content

Instantly share code, notes, and snippets.

View AlexRiina's full-sized avatar

Alex Riina AlexRiina

View GitHub Profile
@AlexRiina
AlexRiina / deoptional.py
Last active August 23, 2020 23:02
remove Optional[] annotation wrappers where redundant
"""
Optional[] is implied in arguments when the default value is None. Leaving it
out is a matter of personal preference and I prefer to leave it out in favor of
shorter lines with not obvious behavior.
This script removes unnecessary Optional declarations in arguments.
WARNING: this updates files in-place.
"""
@AlexRiina
AlexRiina / denest_imports.py
Last active March 20, 2022 21:27
Remove layers from deep imports where possible
"""
Search for imports that are not at the top-level and replace them with
top-level imports.
from x.y import Z -> from x import Z
NOTE: doesn't handle comments or `import x as y`
"""
import argparse