Skip to main content

cofe

A modular counterfactual python-compatible environment.

AST Transformations

For all Python AST transformations, I focused on name based changes rather than structural changes, as the code must still be valid python in order to run from this point. What follows is a list of all transformation classes and their intended use. A strict transformer essentially means it does not allow the <self.new> value to exist in the AST tree.

  • StrictCallTransformer: Changes all instances of ast.Call with the value <self.old> to <self.new>. e.g. foo() -> bar()
  • StrictFuncDefTransformer: Changes all instances of ast.FuncDef with the value <self.old> to <self.new>. e.g. def foo() -> def bar()
  • StrictImportTransformer: Changes all instances of ast.Import with the value <self.old> to <self.new>. Additionally sets <asname=self.new>. e.g. import system -> import sys as system
  • StrictImportFromTransformer: Changes all instances of the ast.ImportFrom with the value <self.old> to <self.new>. e.g. from path_system import Path -> from pathlib import Path.
  • AggregateFuncTransformer: acts as the union between StrictCallTransformer and StrictFuncDefTransformer. Meant to be used to modify internally defined methods.
  • AggregateImportTransformer: acts as the union between StrictImportTransformer and StrictImportFromTransformer. Meant to be used to modify externally imported API (i.e. os, sys, requests, etc.).

Example use cases can be found in the test files.

Grammar Transformations

For all Grammar transformations, I focused on changing the syntactic structure of Python, including keywords, format and other base rules of the language. What follows are a list of the relevant classes in the file.

  • GrammarWrapper: A helper class and an extension of pegen.grammar.Grammar. Gathers all instances of classes that share the same value, using the assumption that they are meant to be pointing at the same value. Allows for easily modifying instances of these values.
  • RenameLeaf: Renames either all StringLeaf's (pegen grammar literal) or NameLeaf's (pegen grammar reference) that have the value <self.old> to <self.new>
  • RenameRule: Renames the rule with the name <self.old> to <self.new>. Additionally uses RenameLeaf(NameLeaf, self.old, self.new) to rename all references to the rule.
  • ReplaceRuleBoady: A more user controlled class allowing for complete control over how a rule works. Should be used first as it does not merge well with Renaming.
  • InjectAlt: Another high-control class allowing the injection of an entirely new Alt branch for one rule. Should be used second.

Release files for cofe 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cofe 0.1.0
File Size Uploaded
cofe-0.1.0.tar.gz 15.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for cofe 0.1.0
File Interpreter ABI Platform
cofe-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 31.1 kB

Release files / cofe-0.1.0.tar.gz

Download URL cofe-0.1.0.tar.gz
Size 15.2 kB
Tags Source
SHA-256 checksum
How to use checksums
8b41ed5e1c85a1e78286485690b2c55c2d09215408ae3a655a25a006749c45d4
BLAKE2b-256 checksum
How to use checksums
5859afed6caa2d4a36bf06dd8ce51744348c30d2ea4b6f2345304f555cf83955
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / cofe-0.1.0-py3-none-any.whl

Download URL cofe-0.1.0-py3-none-any.whl
Size 15.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e29b7d7cb4b932f9eb57012a4948a47eefa804bbb1f1c5ffe8e232567ae865f5
BLAKE2b-256 checksum
How to use checksums
02839f678235e036e60d82a211207b859f39929d8086d5dc19e5e0d9d51cc6de
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release history Release notifications | RSS feed

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page