I just finished adding type annotations to a 10-year old python codebase (for type-checking with the magnificent mypy
).
I had to do stuff like this:
find . -type f -iname \*A_mapper.py | while read ANS ; do
cat "$ANS" | \
sed 's/def OnBasic(\([^,:]*\), \([^,:]*\), \([^,:]*\)):$/def OnBasic(\1: str, \2: AsnBasicNode, \3: AST_Leaftypes) -> None:/' | \
sed 's/def OnChoice(\([^,:]*\), \([^,:]*\), \([^,:]*\)):$/def OnChoice(\1: str, \2: AsnChoice, \3: AST_Leaftypes) -> None:/' | \
sed 's/def OnSequence(([^,:]), ([^,:]), ([^,:]*)):$/def OnSequence(\1: str, \2: AsnSequenceOrSet, \3: AST_Leaftypes) -> None:/' | \