查找代码对象及其引用
项目描述
Codefind
- 从文件名和qualname查找代码对象
- 查找具有特定代码的所有函数
- 更改函数的代码
- 由 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
简单用法
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
更新所有闭包
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
项目详情
下载文件
下载适用于您平台的文件。如果您不确定选择哪个,请了解更多关于 安装软件包 的信息。
源代码分布
codefind-0.1.7.tar.gz (20.0 kB 查看散列)
构建分布
codefind-0.1.7-py3-none-any.whl (3.9 kB 查看散列)
关闭
codefind-0.1.7.tar.gz的散列
算法 | 哈希摘要 | |
---|---|---|
SHA256 | a2ec8a2c0180399ea838dfcdcc344ca89f97b8aa293bc17b22b2c023aba06fbc |
|
MD5 | 0c3c92e9e2203a7382162882c09f5d83 |
|
BLAKE2b-256 | e5fb029e384b0225ea3401fc19f402af63d161462d19091dbf6b50f85cfc4b91 |
关闭
codefind-0.1.7-py3-none-any.whl的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 5f1305b0992185cc87f28925c4449d04a256389099d46a489e619a296a802a29 |
|
MD5 | c7521e76d877bb7684180c8b61557ecf |
|
BLAKE2b-256 | 1d2ef6403d675c1a99a40d076d62ed9759b8863d1ac8119508e902cb0a33691d |