Re: How to find the full class name for a frame
On 04/08/2023 15.34, Jason Friedman via Python-list wrote: import inspect def my_example(arg1, arg2): print(inspect.stack()[0][3]) my_frame = inspect.currentframe() args,_,_,values = inspect.getargvalues(my_frame) args_rendered = [f"{x}: {values[x]}" for x in args] print(args_rendered) my_example("a", 1) The above "works" in the sense it prints what I want, namely the method name (my_example) and the arguments it was called with. The above didn't 'work' - please copy-paste and ensure that the email-client is respecting indentation. My question is: let's say I wanted to add a type hint for my_frame. my_frame: some_class_name = inspect.currentframe() What would I put for some_class_name? "frame" (without quotations) is not recognized, Nor is inspect.frame. We know Python code is executed in an execution frame. (https://docs.python.org/3/reference/executionmodel.html?highlight=frame) We are told "Frame objects Frame objects represent execution frames." (https://docs.python.org/3/reference/datamodel.html?highlight=frame). The word "represent" conflicts with the idea of "are". 'Under the hood' inspect calls sys._current_frames() (https://docs.python.org/3/library/sys.html?highlight=frame). That code is: def _getframe(*args, **kwargs): # real signature unknown """ Return a frame object from the call stack. If optional integer depth is given, return the frame object that many calls below the top of the stack. If that is deeper than the call stack, ValueError is raised. The default for depth is zero, returning the frame at the top of the call stack. This function should be used for internal and specialized purposes only. """ pass Which rather suggests that if the sys library doesn't know the signature, then neither typing nor we mere-mortals are going to do so, either. Theory: the concept of a frame does not really exist at the Python-level (remember "represents"). Frames (must) exist at the C-level (https://docs.python.org/3/c-api/frame.html?highlight=frame#c.PyFrameObject) of the virtual-machine - where typing is not a 'thing'. It's an interesting question. Perhaps a better mind than mine can give a better answer? -- Regards, =dn -- https://mail.python.org/mailman/listinfo/python-list
How to find the full class name for a frame
import inspect def my_example(arg1, arg2): print(inspect.stack()[0][3]) my_frame = inspect.currentframe() args,_,_,values = inspect.getargvalues(my_frame) args_rendered = [f"{x}: {values[x]}" for x in args] print(args_rendered) my_example("a", 1) The above "works" in the sense it prints what I want, namely the method name (my_example) and the arguments it was called with. My question is: let's say I wanted to add a type hint for my_frame. my_frame: some_class_name = inspect.currentframe() What would I put for some_class_name? "frame" (without quotations) is not recognized, Nor is inspect.frame. -- https://mail.python.org/mailman/listinfo/python-list
[Python-announce] Django-Compat-Patcher 0.12 released
Hello everyone, I'm pleased to announce the release of Django-Compat-Patcher 0.12, which now includes 86 compatibility shims ranging from Django 1.6 to 4.2 If your Django project is incompatible with handy pluggable apps, or if you reach the depths of dependency hell when attempting to mass-upgrade your packages, no panic! Just drop this django compatibility patcher into your project, and keep your developments going forward, while dependency conflicts are slowly sorted out in bugtrackers. As a proof-of-concept, the Pychronia alternate reality portal (https://github.com/ChrysalisTeam/pychronia) is kept perfectly functional on Django 4.2, while still having Django 1.10 constructs like "views as dotted strings" (but don't do that for your own projects of course, alternative tools like django-compat or django-codemod will help you migrate your own codebase). Enjoy your decade-long backward compatibility, and get in touch if some compatibility shims are missing for you. Pascal Repository : https://github.com/pakal/django-compat-patcher Download : https://pypi.org/project/django-compat-patcher/ PS: Pip might block on theoretical dependency conflicts even though Django-Compat-Patcher would solve them anyway; so you might have to bypass the Pip dependency resolver, until some escape hatches are implemented in it. ___ Python-announce-list mailing list -- python-announce-list@python.org To unsubscribe send an email to python-announce-list-le...@python.org https://mail.python.org/mailman3/lists/python-announce-list.python.org/ Member address: arch...@mail-archive.com
[Python-announce] RSFile v2.2 released
Dear pythoneers, I'm pleased to announce a little update of the RSFile I/O Library, bringing support for recent Python versions. RSFile provides drop-in replacements for io classes and for the open() builtin. Its goal is to provide a cross-platform, reliable, and comprehensive synchronous file I/O API, with advanced features like fine-grained opening modes, shared/exclusive file record locking, thread-safety, cache synchronization, file descriptor inheritability, and handy stat getters (size, inode, times...). Possible use cases for this library: write to logs concurrently without ending up with garbled data, manipulate sensitive data like disk-based databases, synchronize heterogeneous producer/consumer processes when multiprocessing semaphores aren't an option... Unix users might particularly be interested by the workaround that this library provides, concerning the weird semantic of fcntl() locks (when any descriptor to a disk file is closed, the process loses ALL locks acquired on this file through any descriptor). RSFile has been tested with CPython 3.7+, on Windows/Linux/Mac systems, and should work on other python implementations The technical documentation of RSFile includes a comprehensive description of concepts and gotchas encountered while developing this library, which could be useful to anyone interested in getting in touch with gory file I/O details. Downloads: https://pypi.python.org/pypi/RSFile Documentation: http://rsfile.readthedocs.io/en/latest/ Repository: https://github.com/pakal/rsfile PS: The implementation is currently pure-python, so if you need high performances, using standard python streams in parallel will remain necessary. Also, do not use non-blocking streams with this library or with the IO module in general, lots of things could go wrong... ___ Python-announce-list mailing list -- python-announce-list@python.org To unsubscribe send an email to python-announce-list-le...@python.org https://mail.python.org/mailman3/lists/python-announce-list.python.org/ Member address: arch...@mail-archive.com