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.2

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.2
File Size Uploaded
cofe-0.1.2.tar.gz 35.6 kB Details

Built distribution (wheel)

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

Total release size: 67.8 kB

Release files / cofe-0.1.2.tar.gz

Download URL cofe-0.1.2.tar.gz
Size 35.6 kB
Tags Source
SHA-256 checksum
How to use checksums
4bf16ffb1580c4b1f7cdcd6e3461b07ba3db8620fbbc28dd9019a7a88e53fde7
BLAKE2b-256 checksum
How to use checksums
462f2a7c42c26b02049fe8e16597f780db0e9e44b0182ebe0d235fef9a7b141c
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.2-py3-none-any.whl

Download URL cofe-0.1.2-py3-none-any.whl
Size 32.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
76330e40ca3fd5ab395fcb8b9ca0b5762c34967b0d24cb1484df8a62e0410d8a
BLAKE2b-256 checksum
How to use checksums
43f0540fe3412850099dc7951138c36b68ef87a492ebca14d88a3f1621d759e1
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

This release

0.1.2 This release

2 release files

0.1.1

2 release files

0.1.0

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