3.7.8 String Trace

0 views
Skip to first unread message

Manuela

unread,
Aug 5, 2024, 12:40:51 AM8/5/24
to plunpiseti
Bothof these issues are fixed by postponing the evaluation ofannotations. Instead of compiling code which executes expressions inannotations at their definition time, the compiler stores the annotationin a string form equivalent to the AST of the expression in question.If needed, annotations can be resolved at runtime usingtyping.get_type_hints(). In the common case where this is notrequired, the annotations are cheaper to store (since short stringsare interned by the interpreter) and make startup time faster.

PEP 538 updates the default interpreter command line interface toautomatically coerce that locale to an available UTF-8 based locale asdescribed in the documentation of the new PYTHONCOERCECLOCALEenvironment variable. Automatically setting LC_CTYPE this way means thatboth the core interpreter and locale-aware C extensions (such asreadline) will assume the use of UTF-8 as the default text encoding,rather than ASCII.


As part of this change, the default error handler for stdin andstdout is now surrogateescape (rather than strict) whenusing any of the defined coercion target locales (currently C.UTF-8,C.utf8, and UTF-8). The default error handler for stderrcontinues to be backslashreplace, regardless of locale.


Locale coercion is silent by default, but to assist in debugging potentiallylocale related integration problems, explicit warnings (emitted directly onstderr) can be requested by setting PYTHONCOERCECLOCALE=warn.This setting will also cause the Python runtime to emit a warning if thelegacy C locale remains active when the core interpreter is initialized.


The UTF-8 mode is enabled by default when the locale is C or POSIX, andthe PEP 538 locale coercion feature fails to change it to a UTF-8 basedalternative (whether that failure is due to PYTHONCOERCECLOCALE=0 being set,LC_ALL being set, or the lack of a suitable target locale).


Built-in breakpoint() calls sys.breakpointhook(). By default, thelatter imports pdb and then calls pdb.set_trace(), but by bindingsys.breakpointhook() to the function of your choosing, breakpoint() canenter any debugger. Additionally, the environment variablePYTHONBREAKPOINT can be set to the callable of your debugger ofchoice. Set PYTHONBREAKPOINT=0 to completely disable built-inbreakpoint().


While Python provides a C API for thread-local storage support; the existingThread Local Storage (TLS) API has usedint to represent TLS keys across all platforms. This has notgenerally been a problem for officially support platforms, but that is neitherPOSIX-compliant, nor portable in any practical sense.


Note that on platforms where the native TLS key is defined in a way that cannotbe safely cast to int, all functions of the existing TLS API will beno-op and immediately return failure. This indicates clearly that the old APIis not supported on platforms where it cannot be used reliably, and that noeffort will be made to add such support.


The default handling of DeprecationWarning has been changed such thatthese warnings are once more shown by default, but only when the codetriggering them is running directly in the __main__ module. As a result,developers of single file scripts and those using Python interactively shouldonce again start seeing deprecation warnings for the APIs they use, butdeprecation warnings triggered by imported application, library and frameworkmodules will continue to be hidden by default.


DeprecationWarning: displayed by default only in __main__ and whenrunning tests, recommended for warnings intended to be seen by other Pythondevelopers where a version upgrade may result in changed behaviour or anerror.


Previously both DeprecationWarning and PendingDeprecationWarningwere only visible when running tests, which meant that developers primarilywriting single file scripts or using Python interactively could be surprisedby breaking changes in the APIs they used.


Initially PEP 484 was designed in such way that it would not introduce anychanges to the core CPython interpreter. Now type hints and the typingmodule are extensively used by the community, so this restriction is removed.The PEP introduces two special methods __class_getitem__() and__mro_entries__, these methods are now used by most classes and specialconstructs in typing. As a result, the speed of various operationswith types increased up to 7 times, the generic types can be used withoutmetaclass conflicts, and several long standing bugs in typing module arefixed.


Python has traditionally checked the up-to-dateness of bytecode cache files(i.e., .pyc files) by comparing the source metadata (last-modified timestampand size) with source metadata saved in the cache file header when it wasgenerated. While effective, this invalidation method has its drawbacks. Whenfilesystem timestamps are too coarse, Python can miss source updates, leading touser confusion. Additionally, having a timestamp in the cache file isproblematic for build reproducibility andcontent-based build systems.


The new -X dev command line option or the newPYTHONDEVMODE environment variable can be used to enablePython Development Mode. When in development mode, Python performsadditional runtime checks that are too expensive to be enabled by default.See Python Development Mode documentation for the fulldescription.


An await expression and comprehensions containing anasync for clause were illegal in the expressions informatted string literals due to a problem with theimplementation. In Python 3.7 this restriction was lifted.


In order to better support dynamic creation of stack traces,types.TracebackType can now be instantiated from Python code, andthe tb_next attribute ontracebacks is now writable.(Contributed by Nathaniel J. Smith in bpo-30579.)


When using the -m switch, sys.path[0] is now eagerly expandedto the full starting directory path, rather than being left as the emptydirectory (which allows imports from the current working directory at thetime when an import occurs)(Contributed by Nick Coghlan in bpo-33053.)


The new contextvars module and a set ofnew C APIs introducesupport for context variables. Context variables are conceptuallysimilar to thread-local variables. Unlike TLS, context variablessupport asynchronous code correctly.


The asyncio and decimal modules have been updated to useand support context variables out of the box. Particularly the activedecimal context is now stored in a context variable, which allowsdecimal operations to work with the correct context in asynchronous code.


The new asyncio.get_running_loop() function returns the currentlyrunning loop, and raises a RuntimeError if no loop is running.This is in contrast with asyncio.get_event_loop(), which will createa new event loop if none is running.(Contributed by Yury Selivanov in bpo-32269.)


The new StreamWriter.wait_closed()coroutine method allows waiting until the stream writer is closed. The newStreamWriter.is_closing() methodcan be used to determine if the writer is closing.(Contributed by Andrew Svetlov in bpo-32391.)


It is now possible to control how instances of asyncio.Server beginserving. Previously, the server would start serving immediately when created.The new start_serving keyword argument toloop.create_server() andloop.create_unix_server(),as well as Server.start_serving(), andServer.serve_forever()can be used to decouple server instantiation and serving. The newServer.is_serving() method returns Trueif the server is serving. Server objects are nowasynchronous context managers:


compileall.compile_dir() learned the new invalidation_mode parameter,which can be used to enablehash-based .pyc invalidation. The invalidationmode can also be specified on the command line using the new--invalidation-mode argument.(Contributed by Benjamin Peterson in bpo-31650.)


The dis() function is now able todisassemble nested code objects (the code of comprehensions, generatorexpressions and nested functions, and the code used for building nestedclasses). The maximum depth of disassembly recursion is controlled bythe new depth parameter.(Contributed by Serhiy Storchaka in bpo-11822.)


In Python 3.8, attempting to check for non-Enum objects in Enumclasses will raise a TypeError (e.g. 1 in Color); similarly,attempting to check for non-Flag objects in a Flag member willraise TypeError (e.g. 1 in Perm.RW); currently, both operationsreturn False instead and are deprecated.(Contributed by Ethan Furman in bpo-33217.)


The new gc.freeze() function allows freezing all objects trackedby the garbage collector and excluding them from future collections.This can be used before a POSIX fork() call to make the GC copy-on-writefriendly or to speed up collection. The new gc.unfreeze() functionsreverses this operation. Additionally, gc.get_freeze_count() canbe used to obtain the number of frozen objects.(Contributed by Li Zekun in bpo-31558.)


SimpleHTTPRequestHandler now supports the HTTPIf-Modified-Since header. The server returns the 304 response status ifthe target file was not modified after the time specified in the header.(Contributed by Pierre Quentel in bpo-29654.)


SimpleHTTPRequestHandler accepts the new directoryargument, in addition to the new --directory command line argument.With this parameter, the server serves the specified directory, by default ituses the current working directory.(Contributed by Stphane Wirtel and Julien Palard in bpo-28707.)


Module Browser (on the File menu, formerly called Class Browser),now displays nested functions and classes in addition to top-levelfunctions and classes.(Contributed by Guilherme Polo, Cheryl Sabella, and Terry Jan Reedyin bpo-1612262.)


The font sample now includes a selection of non-Latin characters so thatusers can better see the effect of selecting a particular font.(Contributed by Terry Jan Reedy in bpo-13802.)The sample can be edited to include other characters.(Contributed by Serhiy Storchaka in bpo-31860.)


The IDLE features formerly implemented as extensions have been reimplementedas normal features. Their settings have been moved from the Extensions tabto other dialog tabs.(Contributed by Charles Wohlganger and Terry Jan Reedy in bpo-27099.)

3a8082e126
Reply all
Reply to author
Forward
0 new messages