3 ms·
For an example of what I mean, check out the https://pypi.org/project/aioify/ https://pypi.org/project/aioify/ library. This intercepts all of the function and
by nonameiguess 6y ago
For an example of what I mean, check out the https://pypi.org/project/aioify/ https://pypi.org/project/aioify/ library. This intercepts all of the function and method definitions in a module as they are being imported and rewrites them on the fly to turn all normal functions into async functions.
The language designers definitely took the path of we're just going to assume you know what you're doing and give you absolutely every last foot of rope you could possibly want to hang yourself with.
It does make things fast and easy. See all of the complaints here lately about having to rewrite significant parts of an application to become async as soon as any part of it becomes async? Not a problem in Python. There's a library to just automatically rewrite all code as it is being imported, at the cost that the code you're actually running is not the code you see in your repos.
- willcipriano 6y agoYou can kinda sorta make private variables in Python with some namespace abuse: def make_get_private(var): . . . .private_var = var . . . .def get_private(): . . . . . . . .return private_var . . . .return get_private get_private = make_get_private("spam") You can't readily modify private_var after it is set in this case, you could also make and return a set_private function as well. I imagine you could do a whole module like this and then have it create it's functions at runtime to produce this "private" namespace. It would be a mess though.