3.4 New Parser 4 Other Language Changes 5 • __import__() now raises$_{ImportError}$instead of$_{ValueError}$, which used to occur when a relative import went past its top-level package. (Contributed by Ngalim Siregar in bpo-37444.) • Python now gets the absolute path of the script filename specified on the command line (ex: python3 script.py ): the __file__ attribute of the __main__ module became an absolute path, rather than a relative path. These paths now remain valid after the current directory is changed by$_{os.chdir()}$ . As a side effect, the traceback also displays the absolute path for$_{__main__}$ module frames in this case. (Con- tributed by Victor Stinner in bpo-20443.) • In the Python Development Mode and in debug build, the encoding and errors arguments are now checked for string encoding and decoding operations. Examples:$_{open()}$ ,$_{str.encode()}$ and$_{bytes.decode()}$ . • "".replace("", s, n) now returns$_{s}$ instead of an empty string for all non-zero$_{n}$. It is now consistent with$_{"".replace("", s)}$ . There are similar changes for$_{bytes}$and$_{bytearray}$objects. (Contributed by Serhiy Storchaka in bpo-28029.) • Any valid expression can now be used as a decorator. Previously, the grammar was much more restrictive. See PEP 614 for details. (Contributed by Brandt Bucher in bpo-39702.) • Improved help for the$_{typing}$module. Docstrings are now shown for all special forms and special generic aliases (like$_{Union}$ and$_{List}$ ). Using$_{help()}$ with generic alias like$_{List[int]}$ will show the help for the correspondent concrete type ($_{list}$in this case). (Contributed by Serhiy Storchaka in bpo-40257.) • Parallel running of$_{aclose()}$ /$_{asend()}$ /$_{athrow()}$ is now prohibited, and$_{ag_running}$ now reflects the actual running status of the async generator. (Contributed by Yury Selivanov in bpo-30773.) • Unexpected errors in calling the$_{__iter__}$ method are no longer masked by$_{TypeError}$ in the$_{in}$ operator and functions$_{contains()}$ ,$_{indexOf()}$ and$_{countOf()}$ of the$_{operator}$ module. (Contributed by Serhiy Storchaka in bpo-40824.) • Unparenthesized lambda expressions can no longer be the expression part in an$_{if}$ clause in comprehensions and generator expressions. See bpo-41848 and bpo-43755 for details. Python 3.9 uses a new parser, based on PEG instead of LL(1). The new parser’s performance is roughly comparable to that of the old parser, but the PEG formalism is more flexible than LL(1) when it comes to designing new language features. We’ll start using this flexibility in Python 3.10 and later. The$_{ast}$module uses the new parser and produces the same AST as the old parser. In Python 3.10, the old parser will be deleted and so will all functionality that depends on it (primarily the$_{parser}$ module, which has long been deprecated). In Python 3.9 only , you can switch back to the LL(1) parser using a command line switch ( -X oldparser ) or an environment variable ( PYTHONOLDPARSER=1 ). See PEP 617 for more details. (Contributed by Guido van Rossum, Pablo Galindo and Lysandros Nikolaou in bpo-40334.) By default, for best performance, the errors argument is only checked at the first encoding/decoding error and the encoding argument is sometimes ignored for empty strings. (Contributed by Victor Stinner in bpo-37388.)