:func:`functools.singledispatch` decorator, and :pep:`443`.
generic type
- A :term:`type` that can be parameterized; typically a container like
- :class:`list`. Used for :term:`type hints <type hint>` and
+ A :term:`type` that can be parameterized; typically a
+ :ref:`container class<sequence-types>` such as :class:`list` or
+ :class:`dict`. Used for :term:`type hints <type hint>` and
:term:`annotations <annotation>`.
- See :pep:`483` for more details, and :mod:`typing` or
- :ref:`generic alias type <types-genericalias>` for its uses.
+ For more details, see :ref:`generic alias types<types-genericalias>`,
+ :pep:`483`, :pep:`484`, :pep:`585`, and the :mod:`typing` module.
GIL
See :term:`global interpreter lock`.
# var.get() would raise a LookupError.
-.. class:: contextvars.Token
+.. class:: Token
*Token* objects are returned by the :meth:`ContextVar.set` method.
They can be passed to the :meth:`ContextVar.reset` method to revert
components copied.
This module does not copy types like module, method, stack trace, stack frame,
-file, socket, window, array, or any similar types. It does "copy" functions and
+file, socket, window, or any similar types. It does "copy" functions and
classes (shallow and deeply), by returning the original object unchanged; this
is compatible with the way these are treated by the :mod:`pickle` module.
The following functions all create :ref:`socket objects <socket-objects>`.
-.. function:: socket(family=AF_INET, type=SOCK_STREAM, proto=0, fileno=None)
+.. class:: socket(family=AF_INET, type=SOCK_STREAM, proto=0, fileno=None)
Create a new socket using the given address family, socket type and protocol
number. The address family should be :const:`AF_INET` (the default),
becomes an alias to the :c:func:`PyObject_NewVar` macro. They no longer
access directly the :c:member:`PyTypeObject.tp_basicsize` member.
- * :c:func:`PyType_HasFeature` now always calls :c:func:`PyType_GetFlags`.
- Previously, it accessed directly the :c:member:`PyTypeObject.tp_flags`
- member when the limited C API was not used.
-
* :c:func:`PyObject_GET_WEAKREFS_LISTPTR` macro was converted to a function:
the macro accessed directly the :c:member:`PyTypeObject.tp_weaklistoffset`
member.
/*--start constants--*/
#define PY_MAJOR_VERSION 3
#define PY_MINOR_VERSION 9
-#define PY_MICRO_VERSION 8
+#define PY_MICRO_VERSION 9
#define PY_RELEASE_LEVEL PY_RELEASE_LEVEL_FINAL
#define PY_RELEASE_SERIAL 0
/* Version as a string */
-#define PY_VERSION "3.9.8"
+#define PY_VERSION "3.9.9"
/*--end constants--*/
/* Version as a single 4-byte hex number, e.g. 0x010502B2 == 1.5.2b2.
# namespace for the relevant parts.
subnamespace, arg_strings = parser.parse_known_args(arg_strings, None)
for key, value in vars(subnamespace).items():
- if not hasattr(namespace, key):
- setattr(namespace, key, value)
+ setattr(namespace, key, value)
if arg_strings:
vars(namespace).setdefault(_UNRECOGNIZED_ARGS_ATTR, [])
if action.default is not SUPPRESS:
setattr(namespace, action.dest, action.default)
+ # add any parser defaults that aren't present
+ for dest in self._defaults:
+ if not hasattr(namespace, dest):
+ setattr(namespace, dest, self._defaults[dest])
+
# parse the arguments and exit if there are any errors
if self.exit_on_error:
try:
else:
namespace, args = self._parse_known_args(args, namespace)
- # add any parser defaults that aren't present
- for dest in self._defaults:
- if not hasattr(namespace, dest):
- setattr(namespace, dest, self._defaults[dest])
-
if hasattr(namespace, _UNRECOGNIZED_ARGS_ATTR):
args.extend(getattr(namespace, _UNRECOGNIZED_ARGS_ATTR))
delattr(namespace, _UNRECOGNIZED_ARGS_ATTR)
set of components copied
This version does not copy types like module, class, function, method,
-nor stack trace, stack frame, nor file, socket, window, nor array, nor
-any similar types.
+nor stack trace, stack frame, nor file, socket, window, nor any
+similar types.
Classes can use the same interfaces to control copying that they use
to control pickling: they can define methods called __getinitargs__(),
def children(self):
with suppress(Exception):
- return os.listdir(self.root or '')
+ return os.listdir(self.root or '.')
with suppress(Exception):
return self.zip_children()
return []
import argparse
import json
import sys
+from pathlib import Path
def main():
help='a JSON file to be validated or pretty-printed',
default=sys.stdin)
parser.add_argument('outfile', nargs='?',
- type=argparse.FileType('w', encoding="utf-8"),
+ type=Path,
help='write the output of infile to outfile',
- default=sys.stdout)
+ default=None)
parser.add_argument('--sort-keys', action='store_true', default=False,
help='sort the output of dictionaries alphabetically by key')
parser.add_argument('--no-ensure-ascii', dest='ensure_ascii', action='store_false',
dump_args['indent'] = None
dump_args['separators'] = ',', ':'
- with options.infile as infile, options.outfile as outfile:
+ with options.infile as infile:
try:
if options.json_lines:
objs = (json.loads(line) for line in infile)
else:
- objs = (json.load(infile), )
- for obj in objs:
- json.dump(obj, outfile, **dump_args)
- outfile.write('\n')
+ objs = (json.load(infile),)
+
+ if options.outfile is None:
+ out = sys.stdout
+ else:
+ out = options.outfile.open('w', encoding='utf-8')
+ with out as outfile:
+ for obj in objs:
+ json.dump(obj, outfile, **dump_args)
+ outfile.write('\n')
except ValueError as e:
raise SystemExit(e)
# -*- coding: utf-8 -*-
-# Autogenerated by Sphinx on Fri Nov 5 20:19:23 2021
+# Autogenerated by Sphinx on Mon Nov 15 18:21:10 2021
topics = {'assert': 'The "assert" statement\n'
'**********************\n'
'\n'
xparser.set_defaults(foo=2)
self.assertEqual(NS(foo=2), parser.parse_args(['X']))
- def test_set_defaults_on_subparser_with_namespace(self):
- parser = argparse.ArgumentParser()
- xparser = parser.add_subparsers().add_parser('X')
- xparser.set_defaults(foo=1)
- self.assertEqual(NS(foo=2), parser.parse_args(['X'], NS(foo=2)))
-
def test_set_defaults_same_as_add_argument(self):
parser = ErrorRaisingArgumentParser()
parser.set_defaults(w='W', x='X', y='Y', z='Z')
self.assertEqual(out, b'')
self.assertEqual(err, b'')
+ def test_writing_in_place(self):
+ infile = self._create_infile()
+ rc, out, err = assert_python_ok('-m', 'json.tool', infile, infile)
+ with open(infile, "r", encoding="utf-8") as fp:
+ self.assertEqual(fp.read(), self.expect)
+ self.assertEqual(rc, 0)
+ self.assertEqual(out, b'')
+ self.assertEqual(err, b'')
+
def test_jsonlines(self):
args = sys.executable, '-m', 'json.tool', '--json-lines'
process = subprocess.run(args, input=self.jsonlines_raw, capture_output=True, text=True, check=True)
def test_invalid_line_continuation_error_position(self):
self._check_error(r"a = 3 \ 4",
"unexpected character after line continuation character",
- lineno=1, offset=(10 if support.use_old_parser() else 9))
+ lineno=1, offset=8)
+ self._check_error('1,\\#\n2',
+ "unexpected character after line continuation character",
+ lineno=1, offset=4)
+ self._check_error('\nfgdfgf\n1,\\#\n2\n',
+ "unexpected character after line continuation character",
+ lineno=3, offset=4)
def test_invalid_line_continuation_left_recursive(self):
# Check bpo-42218: SyntaxErrors following left-recursive rules
items = ('a', 'b', 'c')
textvar = tkinter.StringVar(self.root)
def cb_test(*args):
- self.assertEqual(textvar.get(), items[1])
- success.append(True)
+ success.append(textvar.get())
optmenu = ttk.OptionMenu(self.root, textvar, "a", *items)
optmenu.pack()
- cb_name = textvar.trace("w", cb_test)
+ cb_name = textvar.trace_add("write", cb_test)
optmenu['menu'].invoke(1)
- self.assertEqual(success, [True])
- textvar.trace_vdelete("w", cb_name)
+ self.assertEqual(success, ['b'])
+ self.assertEqual(textvar.get(), 'b')
+ textvar.trace_remove("write", cb_name)
optmenu.destroy()
Python News
+++++++++++
+What's New in Python 3.9.9 final?
+=================================
+
+*Release date: 2021-11-15*
+
+Core and Builtins
+-----------------
+
+- bpo-45738: Fix computation of error location for invalid continuation
+ characters in the parser. Patch by Pablo Galindo.
+
+Library
+-------
+
+- bpo-45235: Reverted an argparse bugfix that caused regression in the
+ handling of default arguments for subparsers. This prevented leaf level
+ arguments from taking precedence over root level arguments.
+
+- bpo-45765: In importlib.metadata, fix distribution discovery for an empty
+ path.
+
+- bpo-45644: In-place JSON file formatting using ``python3 -m json.tool
+ infile infile`` now works correctly, previously it left the file empty.
+ Patch by Chris Wesseling.
+
+Documentation
+-------------
+
+- bpo-45772: ``socket.socket`` documentation is corrected to a class from a
+ function.
+
+- bpo-45392: Update the docstring of the :class:`type` built-in to remove a
+ redundant line and to mention keyword arguments for the constructor.
+
+Windows
+-------
+
+- bpo-45732: Updates bundled Tcl/Tk to 8.6.12.
+
+- bpo-45720: Internal reference to :file:`shlwapi.dll` was dropped to help
+ improve startup time. This DLL will no longer be loaded at the start of
+ every Python process.
+
+
What's New in Python 3.9.8 final?
=================================
Before making the call, the VALUES vector should be initialized
with pointers to the appropriate argument values.
-To call the the function using the initialized ffi_cif, use the
+To call the function using the initialized ffi_cif, use the
ffi_call function:
void ffi_call(ffi_cif *cif, void *fn, void *rvalue, void **avalues);
};
PyDoc_STRVAR(type_doc,
-/* this text signature cannot be accurate yet. will fix. --larry */
-"type(object_or_name, bases, dict)\n"
"type(object) -> the object's type\n"
-"type(name, bases, dict) -> a new type");
+"type(name, bases, dict, **kwds) -> a new type");
static int
type_traverse(PyTypeObject *type, visitproc visit, void *arg)
#include <windows.h>
#include <pathcch.h>
-#include <shlwapi.h>
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#include "python_ver_rc.h"
+#ifndef RT_MANIFEST
+// bpo-45220: Cannot reliably #include RT_MANIFEST from
+// anywhere, so we hardcode it
+#define RT_MANIFEST 24
+#endif
// Include the manifest file that indicates we support all
// current versions of Windows.
1 RT_MANIFEST "python.manifest"
#include "python_ver_rc.h"
+#ifndef RT_MANIFEST
+// bpo-45220: Cannot reliably #include RT_MANIFEST from
+// anywhere, so we hardcode it
+#define RT_MANIFEST 24
+#endif
+
// Include the manifest file that indicates we support all
// current versions of Windows.
1 RT_MANIFEST "python.manifest"
#include "python_ver_rc.h"
+#ifndef RT_MANIFEST
+// bpo-45220: Cannot reliably #include RT_MANIFEST from
+// anywhere, so we hardcode it
+#define RT_MANIFEST 24
+#endif
+
// Include the manifest file that indicates we support all
// current versions of Windows.
1 RT_MANIFEST "python.manifest"
#include "python_ver_rc.h"
+#ifndef RT_MANIFEST
+// bpo-45220: Cannot reliably #include RT_MANIFEST from
+// anywhere, so we hardcode it
+#define RT_MANIFEST 24
+#endif
+
// Include the manifest file that indicates we support all
// current versions of Windows.
2 RT_MANIFEST "python.manifest"
#include "python_ver_rc.h"
+#ifndef RT_MANIFEST
+// bpo-45220: Cannot reliably #include RT_MANIFEST from
+// anywhere, so we hardcode it
+#define RT_MANIFEST 24
+#endif
+
// Include the manifest file that indicates we support all
// current versions of Windows.
1 RT_MANIFEST "python.manifest"
#include <winver.h>
+#ifndef RT_MANIFEST
+// bpo-45220: Cannot reliably #include RT_MANIFEST from
+// anywhere, so we hardcode it
+#define RT_MANIFEST 24
+#endif
+
// Include the manifest file that indicates we support all
// current versions of Windows.
2 RT_MANIFEST "python.manifest"
if NOT "%IncludeLibffiSrc%"=="false" set libraries=%libraries% libffi-3.3.0\r
if NOT "%IncludeSSLSrc%"=="false" set libraries=%libraries% openssl-1.1.1l\r
set libraries=%libraries% sqlite-3.35.5.0\r
-if NOT "%IncludeTkinterSrc%"=="false" set libraries=%libraries% tcl-core-8.6.9.0\r
-if NOT "%IncludeTkinterSrc%"=="false" set libraries=%libraries% tk-8.6.9.0\r
+if NOT "%IncludeTkinterSrc%"=="false" set libraries=%libraries% tcl-core-8.6.12.0\r
+if NOT "%IncludeTkinterSrc%"=="false" set libraries=%libraries% tk-8.6.12.0\r
if NOT "%IncludeTkinterSrc%"=="false" set libraries=%libraries% tix-8.4.3.6\r
set libraries=%libraries% xz-5.2.2\r
set libraries=%libraries% zlib-1.2.11\r
set binaries=\r
if NOT "%IncludeLibffi%"=="false" set binaries=%binaries% libffi-3.3.0\r
if NOT "%IncludeSSL%"=="false" set binaries=%binaries% openssl-bin-1.1.1l\r
-if NOT "%IncludeTkinter%"=="false" set binaries=%binaries% tcltk-8.6.9.0\r
+if NOT "%IncludeTkinter%"=="false" set binaries=%binaries% tcltk-8.6.12.0\r
if NOT "%IncludeSSLSrc%"=="false" set binaries=%binaries% nasm-2.11.06\r
\r
for %%b in (%binaries%) do (\r
<PreprocessorDefinitions Condition="$(IncludeExternals)">_Py_HAVE_ZLIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>\r
</ClCompile>\r
<Link>\r
- <AdditionalDependencies>version.lib;shlwapi.lib;ws2_32.lib;pathcch.lib;%(AdditionalDependencies)</AdditionalDependencies>\r
+ <AdditionalDependencies>version.lib;ws2_32.lib;pathcch.lib;%(AdditionalDependencies)</AdditionalDependencies>\r
</Link>\r
</ItemDefinitionGroup>\r
<ItemGroup>\r
<PropertyGroup>\r
<TclMajorVersion>8</TclMajorVersion>\r
<TclMinorVersion>6</TclMinorVersion>\r
- <TclPatchLevel>9</TclPatchLevel>\r
+ <TclPatchLevel>12</TclPatchLevel>\r
<TclRevision>0</TclRevision>\r
<TkMajorVersion>$(TclMajorVersion)</TkMajorVersion>\r
<TkMinorVersion>$(TclMinorVersion)</TkMinorVersion>\r
msg = "too many levels of indentation";
break;
case E_LINECONT: {
- char* loc = strrchr(p->tok->buf, '\n');
- const char* last_char = p->tok->cur - 1;
- if (loc != NULL && loc != last_char) {
- col_offset = p->tok->cur - loc - 1;
- p->tok->buf = loc;
- } else {
- col_offset = last_char - p->tok->buf - 1;
- }
+ col_offset = p->tok->cur - p->tok->buf - 1;
msg = "unexpected character after line continuation character";
break;
}
msg = "unknown parsing error";
}
- RAISE_ERROR_KNOWN_LOCATION(p, errtype, p->tok->lineno, col_offset, msg);
+ RAISE_ERROR_KNOWN_LOCATION(p, errtype, p->tok->lineno,
+ col_offset >= 0 ? col_offset : 0, msg);
return -1;
}
c = tok_nextc(tok);
if (c != '\n') {
tok->done = E_LINECONT;
- tok->cur = tok->inp;
return ERRORTOKEN;
}
c = tok_nextc(tok);
-This is Python version 3.9.8
+This is Python version 3.9.9
============================
.. image:: https://travis-ci.org/python/cpython.svg?branch=3.9