my first attempted at rewriting this was the OP version, the if. But then I was like NAH WHY NOT JUST:
try:
A['foo'] = B['foo']
except KeyError:
pass
my first attempted at rewriting this was the OP version, the if. But then I was like NAH WHY NOT JUST:
try:
A['foo'] = B['foo']
except KeyError:
pass
but ruff told me no no, don't do that. do this instead:
import contextlib
with contextlib.suppress(KeyError):
A['foo'] = B['foo']
which is not an option I would have considered and I'm wondering if other python programmers agree with that style. My python style unfortunately lags behind because I was stuck in the python 2 mines for so long, so I've missed out on a lot of the python 3 features like this.