Skip to main content

🔧 Semi-automatic rule based editing of Python code 🔧

Project description

fixo

Goals.

  • Light weight, semi-automatic rule-based tool to add type annotations to Python code bases.

  • Apply rule-based edits, and allow the user to pick and choose which edits to accept.

  • Edits are not represented as raw diffs, but as semantic changes to the Python source, which are far more likely to be stable through intermediate changes in the code.

  • The rules to match code and to perform edits can easily be user code.

  • Less than 1k lines of code with testing.

Design sketch

The input to the program would be the output of some other diagnostic tool, like pyrefly or mypy, outputs that are divided into messages, one complete message from the diagnostic tool to the user. In pyrefly it can just be a single line of text.

A message has a file name, a symbol name, and a line number, a column number for the start and end of position in the file.

For each message in the input, and for each rule that that message matches, the rule creates a proposed edit to the message's file, and then writes that edit as a line of JSON into the "edits file"

The user chooses selects which edits to use, initially by just editing the edits file, and soon with a little terminal interface that displays the proposed change in context of the Python source file.

Then the edits file is applied to the code base all at once.

How to write it?

Four main parts need to be written:

  1. Parsing the inputs into messages
  2. Matching messages against rules
  3. Creating an edit from a rule and a matching message
  4. Performing an edit

The hard part: it must easy be for developers to create and perform edits without knowing how to parse a Python file

As of October 1

All the fundamental classes exist and some tests of the trickiest parts of their functionality too - it mostly corresponds to the above.

Now we embark on three specific rules to apply to PyTorch

  1. Add a bool return type annotation to methods and functions that start with _?(is|has)_
  2. Add a bool type annotation to parameters that start with (is|has)_
  3. Add a torch.Tensor type annotation to function (but not method) parameters named self

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

fixo-0.2.0.tar.gz (17.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fixo-0.2.0-py3-none-any.whl (19.6 kB view details)

Uploaded Python 3

File details

Details for the file fixo-0.2.0.tar.gz.

File metadata

  • Download URL: fixo-0.2.0.tar.gz
  • Upload date:
  • Size: 17.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.28 {"installer":{"name":"uv","version":"0.9.28","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for fixo-0.2.0.tar.gz
Algorithm Hash digest
SHA256 d70deab5e9442c40863a2c767293581149ca0429b8d1a292c868e897b4cc2131
MD5 5dc214b686a4db4638d4a70e9723d334
BLAKE2b-256 061967b7745fe69ca7b5c8875291f6786c2c4926a5438f34c92e619190dadc2f

See more details on using hashes here.

File details

Details for the file fixo-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: fixo-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 19.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.28 {"installer":{"name":"uv","version":"0.9.28","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for fixo-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0e5bb6128521ffe26b05980c5648a507c6d4c844d634380253fe1eb83956918e
MD5 e6feb8239e0f937870b2ed16916c2ad3
BLAKE2b-256 9f57c073da58f1f6ee8e5c87042923ca21cf573bfdce4bb005725d4d12b8db52

See more details on using hashes here.

Supported by

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