Find code objects and their referents
Project description
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
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
codefind-0.1.7.tar.gz
(20.0 kB
view details)
Built Distribution
File details
Details for the file codefind-0.1.7.tar.gz
.
File metadata
- Download URL: codefind-0.1.7.tar.gz
- Upload date:
- Size: 20.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: python-httpx/0.27.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a2ec8a2c0180399ea838dfcdcc344ca89f97b8aa293bc17b22b2c023aba06fbc |
|
MD5 | 0c3c92e9e2203a7382162882c09f5d83 |
|
BLAKE2b-256 | e5fb029e384b0225ea3401fc19f402af63d161462d19091dbf6b50f85cfc4b91 |
File details
Details for the file codefind-0.1.7-py3-none-any.whl
.
File metadata
- Download URL: codefind-0.1.7-py3-none-any.whl
- Upload date:
- Size: 3.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-httpx/0.27.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5f1305b0992185cc87f28925c4449d04a256389099d46a489e619a296a802a29 |
|
MD5 | c7521e76d877bb7684180c8b61557ecf |
|
BLAKE2b-256 | 1d2ef6403d675c1a99a40d076d62ed9759b8863d1ac8119508e902cb0a33691d |