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

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

Built distribution (wheel)

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

Total release size: 67.7 kB

Release files / cofe-0.1.1.tar.gz

Download URL cofe-0.1.1.tar.gz
Size 35.6 kB
Tags Source
SHA-256 checksum
How to use checksums
7f766b3a51dc09f6319654cb3200d8ecb489392699d3506f21b9b3d519b2653e
BLAKE2b-256 checksum
How to use checksums
8080c031423676255d27468a28b5dc77439f4298bf7ea6bbeb3529085c04a80a
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.1-py3-none-any.whl

Download URL cofe-0.1.1-py3-none-any.whl
Size 32.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7f581ab2ee1da420ac82cbc38360b1ced2ac575ff50d76e789c5eafc7ff5fbe4
BLAKE2b-256 checksum
How to use checksums
15e560462ab4187897511350d805f7d26f96a72c9b420fcb55e608efd1bddd2a
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

This release

0.1.1 This release

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