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.3.0.tar.gz (39.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.3.0-py3-none-any.whl (19.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: fixo-0.3.0.tar.gz
  • Upload date:
  • Size: 39.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.12 {"installer":{"name":"uv","version":"0.10.12","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.3.0.tar.gz
Algorithm Hash digest
SHA256 6e7aeca3fd860584af6af65046f7a9f84779c7ba7b5473b4e8d6c4ddab96e35e
MD5 4ddb9e4b6c254720888e2d3892b7c304
BLAKE2b-256 ac4418700783ba17d490ba77f5f82a52a28d5a3d7dd0a99c3b9f71d72aa153a8

See more details on using hashes here.

File details

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

File metadata

  • Download URL: fixo-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 19.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.12 {"installer":{"name":"uv","version":"0.10.12","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.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6e2a6ccf57e2d360561cade6de093f03654adf3cb6b02046dd56428d90b61884
MD5 d476f43fc2efc3856586807431c49ee2
BLAKE2b-256 ecba7726d61afd402e5118fc9aef3b17c176e7473a0c45816f1d1db5341e2b42

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