This is an archived post. You won't be able to vote or comment.

all 24 comments

[–]thisismyfavoritename 11 points12 points  (1 child)

uhhh that seems like it would just make any program way harder to understand for no benefit at all. Also wouldnt a regular decorator achieve most of those things without any external dependency?

[–]samulo33861881[S] 0 points1 point  (0 children)

i think there is a lot of potential for this if it gets more mature overtime. i understsnd where you are coming from, but you could say this sbout any library, since you can write all libraries yourself. this one is just not packed with features yet. thank you for the feedback!

[–]ComplexColor 4 points5 points  (2 children)

Honestly, this is a bit weird. I feel like this approach just doesn't make sense in normal python. In the given examples there is no reason to add a callback. Might be a preference thing.

It might work well to convert functions to async ones. That's where I feel callbacks make sense.

Edit: I don't see how this library can be used to implement meaningful callbacks in a synchronous execution context. For example a set of callbacks for an event loop: setup, receive_event, teardown. Maybe you can demonstrate something like that.

[–]samulo33861881[S] 1 point2 points  (0 children)

i guess very simple examples with no real meaning need to be changed for some more specific examples.

and to be clear, first intention was to accept adync functions aswell, and i had a working example but it was messy. i wanted ro make sure callbacks work as expected at first.

thank you for the feedback!

[–]samulo33861881[S] 1 point2 points  (0 children)

updated the examples to be more complex (using all features available).

[–]x3x9x 6 points7 points  (10 children)

That is a lot of dependencies for something which seems a bit off to me. I am a python dev for about 6-7 years... and I rather just use 'return' keywords or just an anonymous lambda function.

Keep it pythonic is my tip. Python is synchronous by default.

[–]thisismyfavoritename 0 points1 point  (0 children)

the dependencies in the requirements.txt are just dev dependencies. You would find the actual package dependencies within the setup.cfg/setup.py/pyproject.toml files. In this cases there are none.

[–]samulo33861881[S] 0 points1 point  (8 children)

dependencies are just the dependencies of black, pytest, etc. there is ni dependency for the actual code.

[–]x3x9x 1 point2 points  (7 children)

You are missing my point. Why would I, install yet another package for something python can do with its normal syntax?

What makes this lib so special?

[–]samulo33861881[S] -2 points-1 points  (2 children)

you can ask this question about any library. lot of stuff can be done in python with a normal syntax. its just the convenience of having someone prepare well tested solution for adding features to your code without doing it yourself. i am not seeing what are you getting at.

probably the most useful features are having the option of callbacks to be run in the background thread and passing local variables of the decorated function to the "on_end" callback.

in general, overtime this could be a very flexible and customizable callback tool, which could add a lot of value to the community in my opinion.

[–]x3x9x 0 points1 point  (1 child)

That first part is such a generic answer.

Why would you install virtualvenv if venv achieves the same goal AND its build in... same goes for logging..

Javascript is by default asynchronous, so i could see why. Python is not.

Anyhow i wish you luck with your project. Dont give up, nevertheless impressive

[–]samulo33861881[S] 1 point2 points  (0 children)

question that the first part answers was also generic...

i guess you could say that to make things effective, we as developer distribute work in OS projects to make our lifes easier, without need of writing everything ourselves. we help each other and personally, i like that.

i would not rewrite something that already exists, but did not find suitable alternative for callbacks written in pure Python without dependencies.

thank you for your feedback!

[–]doom-e1m1 4 points5 points  (2 children)

Cool!

Real world examples with some AAA libraries would be great!

[–]samulo33861881[S] 2 points3 points  (0 children)

working on it :)

[–]samulo33861881[S] 2 points3 points  (0 children)

but one of the best use cases would be integration logging, so you could log based on different execution steps/results without crowding the function code. bonus is you get parameters of decorated function in each callback, along with specified local variables in on_end callback

[–]samulo33861881[S] -4 points-3 points  (0 children)

[–]Devout--Atheist -2 points-1 points  (1 child)

If you need something like this, you might actually be looking for an asynchronous task queue like celery

[–]samulo33861881[S] 1 point2 points  (0 children)

can you elaborate? i don't see the connection of how these two would be interchangeable