Skip to main content

Codefind

  • Find code objects from filename and qualname
  • Find all functions that have a certain code
  • Change the code of functions
  • Used by jurigged

find_code

from codefind import find_code

def f(x):
    return x + x

def adder(x):
    def f(y):
        return x + y

    return f

add1 = adder(1)

assert find_code("f" filename=__file__) is f.__code__

# Can find inner closures
assert find_code("adder", "f", filename=__file__) is add1.__code__

# Also works with module name
assert find_code("adder", "f", module=__module__) is add1.__code__

get_functions

from codefind import get_functions

def f(x):
    return x + x

def adder(x):
    def f(y):
        return x + y

    return f

add1 = adder(1)
add2 = adder(2)
add3 = adder(3)

assert get_functions(f.__code__) == [f]

# Finds all functions with the same code (in any order)
assert set(get_functions(add1.__code__)) == {add1, add2, add3}

conform

Simple usage

from codefind import conform

def f(x):
    return x + x

def g(x):
    return x * x

print(f(5))  # 10
conform(f, g)
print(f(5))  # 25

Updating all closures

def adder(x):
    def f(y):
        return x + y

    return f

def muller(x):
    def f(y):
        return x * y

    return f

add1 = adder(1)
add2 = adder(2)
add3 = adder(3)

print(add1(5))  # 6
print(add2(5))  # 7
print(add3(5))  # 8

conform(add1.__code__, muller(0).__code__)

print(add1(5))  # 5
print(add2(5))  # 10
print(add3(5))  # 15

Metadata

Release files for codefind 0.1.7

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

Source distribution (sdist)

Source distribution for codefind 0.1.7
File Size Uploaded
codefind-0.1.7.tar.gz 20.0 kB Details

Built distribution (wheel)

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

Total release size: 23.9 kB

Release files / codefind-0.1.7.tar.gz

Download URL codefind-0.1.7.tar.gz
Size 20.0 kB
Tags Source
SHA-256 checksum
How to use checksums
a2ec8a2c0180399ea838dfcdcc344ca89f97b8aa293bc17b22b2c023aba06fbc
BLAKE2b-256 checksum
How to use checksums
e5fb029e384b0225ea3401fc19f402af63d161462d19091dbf6b50f85cfc4b91
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-httpx/0.27.2

Release files / codefind-0.1.7-py3-none-any.whl

Download URL codefind-0.1.7-py3-none-any.whl
Size 3.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5f1305b0992185cc87f28925c4449d04a256389099d46a489e619a296a802a29
BLAKE2b-256 checksum
How to use checksums
1d2ef6403d675c1a99a40d076d62ed9759b8863d1ac8119508e902cb0a33691d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-httpx/0.27.2

Release history Release notifications | RSS feed

This release

0.1.7 This release

2 release files

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

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