Comment by kareem_hashash
1 day ago
This Package I have created (*hackwrap*) on May-9-2025, it's a python *decorator-based* package that you can push the boundaries of python rules with it, I saw some of people misunderstanding the usage of this package, so I said why not to tell you about it:
1. equivalent of `async`:
import hackwrap
import asyncio
@hackwrap.asnc
def async_function():
return 'Finished'
print(asyncio.run(async_function())) # Finished
2. inherit from a class:
import hackwrap
class Inherited:
some_attribute = 21
@hackwrap.classinherit(Inherited, init=False)
def withaclass():
pass
print(withaclass.some_attribute) # 21
3. endless functions:
import hackwrap
@hackwrap.endless
def endless_function():
return "this will never return if not thredified"
print(endless_function()) # and it goes forever
4. promote a function to global scope
import hackwrap
def outer_function():
@hackwrap.globe
def inner_function():
print('Called from local scope')
outer_function() # call this function to make python read the wrapper
inner_function() # Called from local scope
5. inherit from a function:
import hackwrap
def parent(*args, **kwargs):
return f'Called from parent, args: {args}, kwargs: {kwargs}'
@hackwrap.inherit(parent, returned='both')
def child(*args, **kwargs):
return f'Called from child, args: {args}, kwargs: {kwargs}'
print(child(1, 2, 3, a=1, b=2, c=3)) # ("Called from child, args: (1, 2, 3), kwargs: {'a': 1, 'b': 2, 'c': 3}", "Called from parent, args: (1, 2, 3), kwargs: {'a': 1, 'b': 2, 'c': 3}")
6. inherit from a module:
import hackwrap, typing
@hackwrap.moduleinherit(typing)
def tping(): pass
print(tping.Literal) # typing.Literal
7. return something when a function is mentioned (my favorite part :)):
import hackwrap
@hackwrap.onment(lambda: hackwrap.this.func()) # onment callback must be a callable
@hackwrap.update_this
def prop():
return 10 # you can replace this with anything you want
print(prop) # 10 (or whatever the function prop returnes)
print(hackwrap.this.func) # <function prop at ...>
the `hackwrap.onment` calls the given call back when one of the function attributes is activated, like, \_\_str\_\_, \_\_add\_\_, \_\_gt\_\_, etc... `hackwrap.update_this` updates the global `hackwrap.this` variable which refers to the current function.
8. making un-mangled functions private:
\# example *.py*
import hackwrap
@hackwrap.private
def private_function(a, b): return a + b
print(private_function(45, 78)) # 123
\# main *.py*
import example
print(example.private_function(45, 78)) # NameError
9. making mangled public:
\# example *.py*
import hackwrap
@hackwrap.public
def __public_one(a, b): return a + b
\# main *.py*
import example
print(example.__public_one(45, 78)) # 123
10. turn async to sync:
import hackwrap
@hackwrap.snc
async def add(a, b):
return a + b
print(add(10, 56)) # 66
11. auto-threadify functions:
import hackwrap, time
@hackwrap.threadify
def main():
while True:
print("I'll be Threaded")
main()
time.sleep(1) # keep printing for a second
12. skipping del keyword:
import hackwrap
@hackwrap.undeletable
def hello():
print("I'm still there")
del hello
hello() # I'm still there
13. simulate functions inheriting from variables:
import hackwrap
@hackwrap.varinherit('Hello World!')
def simulated_str(): pass
print(simulated_str().upper()) # HELLO WORLD!
hope you find that Interesting
No comments yet
Contribute on Hacker News ↗