Change all instances of self to this in one randomly chosen scope per file.
Inspired by David Beazley's toot.
Install from PyPi with your favorite pip invocation:
$ python3 -m pip install randomly-change-selfYou can confirm proper installation via the randomly-change-self CLI:
$ randomly-change-self --help
usage: randomly-change-self [-h] [--replace-with REPLACE_WITH] [--consider-mercury-in-retrograde CONSIDER_MERCURY_IN_RETROGRADE] [filenames ...]
positional arguments:
filenames
options:
-h, --help show this help message and exit
--replace-with REPLACE_WITH
--consider-mercury-in-retrograde CONSIDER_MERCURY_IN_RETROGRADE
A collection of filename(s) to process. While this isn't required, you should probably pass some filename(s) if you want something to happen.
Specify the string to replace "self" with. Defaults to "this"
It's assumed that this value is a valid Python identifier. No validation of this is done, we're all adults here.
Set to True if you only want to make changes if Mercury is in retrograde.
NOTE: Because it turns out that astrophysics is a little challenging and I haven't done it since college, this is currently implemented as an API call to the Mercury Retrograde API. This call should fail gracefully, and if an issue is encountered then your flag will be ignored and your code will get changed anyway.
You can even use this as a pre-commit hook. Wow!
- repo: https://github.com/sco1/randomly-change-self
rev: v0.2.0
hooks:
- id: randomly-change-self
args: [--consider-mercury-in-retrograde=False]