Skip to main content

Change all instances of `self` to `this` in one randomly chosen scope

Project description

randomly-change-self

PyPI - Python Version PyPI PyPI - License pre-commit.ci status Code style: black

Change all instances of self to this in one randomly chosen scope per file.

Inspired by David Beazley's toot.

Installation

Install from PyPi with your favorite pip invocation:

$ python3 -m pip install randomly-change-self

You 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

Arguments

filenames

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.

replace-with

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.

consider-mercury-in-retrograde

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.

Pre-Commit

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]

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

randomly_change_self-0.2.0.tar.gz (4.9 kB view hashes)

Uploaded Source

Built Distribution

randomly_change_self-0.2.0-py3-none-any.whl (5.6 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page