diff --git a/namespace-inject.py b/namespace-inject.py new file mode 100644 index 0000000..d9c4f79 --- /dev/null +++ b/namespace-inject.py @@ -0,0 +1,52 @@ +# import new + + +from types import FunctionType + + +def my_func(pstr: str) -> None: + + def foo() -> None: + print(f"{pstr = }") + + foo() + + +def my_func2(pstr: str) -> None: + foo() + + +def func_test(f: FunctionType) -> None: + print(f"{f.__name__ } = {f}, {f.__code__.co_name = }") + f("narf") + f("zort") + + +def main() -> None: + func_test(my_func) + + fcode = my_func.__code__.replace( + co_name="foo", + co_qualname="foo", + co_nlocals=3, + co_varnames=("pstr", "foo", "lol") + ) + + f = FunctionType( + name="foo", + code=fcode, + globals=my_func.__globals__, + ) + + func_test(f) + + import json + + print(json.dumps({ + name: repr(getattr(f.__code__, name)) + for name in dir(f.__code__) + }, indent=2)) + + +if __name__ == "__main__": + main() diff --git a/poetry.lock b/poetry.lock new file mode 100644 index 0000000..022bbde --- /dev/null +++ b/poetry.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Poetry 1.4.2 and should not be changed by hand. +package = [] + +[metadata] +lock-version = "2.0" +python-versions = "^3.10" +content-hash = "53f2eabc9c26446fbcc00d348c47878e118afc2054778c3c803a0a8028af27d9" diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..5b26a1c --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,16 @@ +[tool.poetry] +name = "cursed-snakes" +version = "0.1.0" +description = "" +authors = ["Jörn-Michael Miehe "] +license = "MIT" +readme = "README.md" +packages = [{include = "cursed_snakes"}] + +[tool.poetry.dependencies] +python = "^3.10" + + +[build-system] +requires = ["poetry-core"] +build-backend = "poetry.core.masonry.api"