Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
3ad52e3
bpo-1635741: Port mmap module to multiphase initialization (GH-19459)
corona10 Jun 5, 2020
087d612
bpo-40874: Update to libmpdec-2.5.0 (GH-20652)
skrah Jun 5, 2020
fef1fae
bpo-19468: delete unnecessary instance check in importlib.reload() (G…
furkanonder Jun 5, 2020
5fe1df1
Fix missing FloatOperation in EXTRA_FUNCTIONALITY path. (#20655)
skrah Jun 5, 2020
161541a
bpo-39791: Refresh importlib.metadata from importlib_metadata 1.6.1. …
jaraco Jun 5, 2020
235f918
bpo-40876: Clarify error message in the csv module (GH-20653)
cool-RR Jun 5, 2020
45af786
bpo-40867: Remove unused include from Module/_randommodule.c (GH-20635)
Jun 5, 2020
b084d1b
bpo-40862: Raise TypeError when const is given to argparse.BooleanOpt…
Jun 5, 2020
a54096e
bpo-40883: Fix memory leak in fstring_compile_expr in parse_string.c …
pablogsal Jun 5, 2020
2e6593d
bpo-40880: Fix invalid read in newline_in_string in pegen.c (#20666)
pablogsal Jun 5, 2020
ba6fd87
Refactor scripts in Tools/peg_generator/scripts (GH-20401)
lysnikolaou Jun 6, 2020
5552850
[workflow] Use gcc problem matcher for Ubuntu action build (GH-18567)
ammaraskar Jun 6, 2020
68874a8
bpo-40870: Invalidate usage of some constants with ast.Name (GH-20649)
isidentical Jun 6, 2020
f7c4e23
bpo-40724: Support setting buffer slots from type specs (GH-20648)
scoder Jun 6, 2020
0e96c41
Update comments to reflect the current API (GH-20682)
rhettinger Jun 6, 2020
b8867e5
Fix return type of test helper function heapctypewithbuffer_releasebu…
Jun 7, 2020
47a23fc
bpo-40898: Remove redundant if statements in tp_traverse (GH-20692)
shihai1991 Jun 7, 2020
2efe18b
bpo-39791: Support file systems that cannot support non-ascii filenam…
jaraco Jun 7, 2020
7633308
Update documentations of strftime function for date, time and datetime.
eiffel-fl Oct 5, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .github/problem-matchers/gcc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"__comment": "Taken from vscode-cpptools's Extension/package.json gcc rule",
"problemMatcher": [
{
"owner": "gcc-problem-matcher",
"pattern": [
{
"regexp": "^(.*):(\\d+):(\\d+):\\s+(?:fatal\\s+)?(warning|error):\\s+(.*)$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5
}
]
}
]
}
2 changes: 2 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ jobs:
OPENSSL_VER: 1.1.1f
steps:
- uses: actions/checkout@v2
- name: Register gcc problem matcher
run: echo "::add-matcher::.github/problem-matchers/gcc.json"
- name: Install Dependencies
run: sudo ./.github/workflows/posix-deps-apt.sh
- name: 'Restore OpenSSL build'
Expand Down
14 changes: 11 additions & 3 deletions Doc/library/importlib.metadata.rst
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ Entry points
The ``entry_points()`` function returns a dictionary of all entry points,
keyed by group. Entry points are represented by ``EntryPoint`` instances;
each ``EntryPoint`` has a ``.name``, ``.group``, and ``.value`` attributes and
a ``.load()`` method to resolve the value.
a ``.load()`` method to resolve the value. There are also ``.module``,
``.attr``, and ``.extras`` attributes for getting the components of the
``.value`` attribute::

>>> eps = entry_points() # doctest: +SKIP
>>> list(eps) # doctest: +SKIP
Expand All @@ -86,6 +88,12 @@ a ``.load()`` method to resolve the value.
>>> wheel = [ep for ep in scripts if ep.name == 'wheel'][0] # doctest: +SKIP
>>> wheel # doctest: +SKIP
EntryPoint(name='wheel', value='wheel.cli:main', group='console_scripts')
>>> wheel.module # doctest: +SKIP
'wheel.cli'
>>> wheel.attr # doctest: +SKIP
'main'
>>> wheel.extras # doctest: +SKIP
[]
>>> main = wheel.load() # doctest: +SKIP
>>> main # doctest: +SKIP
<function main at 0x103528488>
Expand All @@ -94,7 +102,7 @@ The ``group`` and ``name`` are arbitrary values defined by the package author
and usually a client will wish to resolve all entry points for a particular
group. Read `the setuptools docs
<https://setuptools.readthedocs.io/en/latest/setuptools.html#dynamic-discovery-of-services-and-plugins>`_
for more information on entrypoints, their definition, and usage.
for more information on entry points, their definition, and usage.


.. _metadata:
Expand Down Expand Up @@ -235,7 +243,7 @@ method::
"""

The ``DistributionFinder.Context`` object provides ``.path`` and ``.name``
properties indicating the path to search and names to match and may
properties indicating the path to search and name to match and may
supply other relevant context.

What this means in practice is that to support finding distribution package
Expand Down
5 changes: 5 additions & 0 deletions Include/typeslots.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
/* Do not renumber the file; these numbers are part of the stable ABI. */
#if defined(Py_LIMITED_API)
/* Disabled, see #10181 */
#undef Py_bf_getbuffer
#undef Py_bf_releasebuffer
#else
#define Py_bf_getbuffer 1
#define Py_bf_releasebuffer 2
#endif
#define Py_mp_ass_subscript 3
#define Py_mp_length 4
#define Py_mp_subscript 5
Expand Down
1 change: 0 additions & 1 deletion Lib/argparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -857,7 +857,6 @@ class BooleanOptionalAction(Action):
def __init__(self,
option_strings,
dest,
const=None,
default=None,
type=None,
choices=None,
Expand Down
10 changes: 6 additions & 4 deletions Lib/collections/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -760,10 +760,12 @@ def __repr__(self):
# set(cp - cq) == sp - sq
# set(cp | cq) == sp | sq
# set(cp & cq) == sp & sq
# cp.isequal(cq) == (sp == sq)
# cp.issubset(cq) == sp.issubset(sq)
# cp.issuperset(cq) == sp.issuperset(sq)
# cp.isdisjoint(cq) == sp.isdisjoint(sq)
# (cp == cq) == (sp == sq)
# (cp != cq) == (sp != sq)
# (cp <= cq) == (sp <= sq)
# (cp < cq) == (sp < sq)
# (cp >= cq) == (sp >= sq)
# (cp > cq) == (sp > sq)

def __add__(self, other):
'''Add counts from two counters.
Expand Down
8 changes: 4 additions & 4 deletions Lib/importlib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
# Fully bootstrapped at this point, import whatever you like, circular
# dependencies and startup overhead minimisation permitting :)

import types
import warnings


Expand Down Expand Up @@ -136,12 +135,13 @@ def reload(module):
The module must have been successfully imported before.

"""
if not module or not isinstance(module, types.ModuleType):
raise TypeError("reload() argument must be a module")
try:
name = module.__spec__.name
except AttributeError:
name = module.__name__
try:
name = module.__name__
except AttributeError:
raise TypeError("reload() argument must be a module")

if sys.modules.get(name) is not module:
msg = "module {} not in sys.modules"
Expand Down
30 changes: 25 additions & 5 deletions Lib/importlib/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,16 @@ def load(self):
attrs = filter(None, (match.group('attr') or '').split('.'))
return functools.reduce(getattr, attrs, module)

@property
def module(self):
match = self.pattern.match(self.value)
return match.group('module')

@property
def attr(self):
match = self.pattern.match(self.value)
return match.group('attr')

@property
def extras(self):
match = self.pattern.match(self.value)
Expand Down Expand Up @@ -170,7 +180,7 @@ def from_name(cls, name):
"""
for resolver in cls._discover_resolvers():
dists = resolver(DistributionFinder.Context(name=name))
dist = next(dists, None)
dist = next(iter(dists), None)
if dist is not None:
return dist
else:
Expand Down Expand Up @@ -213,6 +223,17 @@ def _discover_resolvers():
)
return filter(None, declared)

@classmethod
def _local(cls, root='.'):
from pep517 import build, meta
system = build.compat_system(root)
builder = functools.partial(
meta.build,
source_dir=root,
system=system,
)
return PathDistribution(zipfile.Path(meta.build_as_zip(builder)))

@property
def metadata(self):
"""Return the parsed metadata for this Distribution.
Expand Down Expand Up @@ -391,7 +412,7 @@ class FastPath:

def __init__(self, root):
self.root = root
self.base = os.path.basename(root).lower()
self.base = os.path.basename(self.root).lower()

def joinpath(self, child):
return pathlib.Path(self.root, child)
Expand All @@ -408,8 +429,8 @@ def zip_children(self):
names = zip_path.root.namelist()
self.joinpath = zip_path.joinpath

return (
posixpath.split(child)[0]
return dict.fromkeys(
child.split(posixpath.sep, 1)[0]
for child in names
)

Expand Down Expand Up @@ -475,7 +496,6 @@ def _search_paths(cls, name, paths):
)



class PathDistribution(Distribution):
def __init__(self, path):
"""Construct a distribution from a path to the metadata directory.
Expand Down
8 changes: 8 additions & 0 deletions Lib/test/test_argparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,14 @@ class TestBooleanOptionalAction(ParserTestCase):
('--no-foo --foo', NS(foo=True)),
]

def test_const(self):
# See bpo-40862
parser = argparse.ArgumentParser()
with self.assertRaises(TypeError) as cm:
parser.add_argument('--foo', const=True, action=argparse.BooleanOptionalAction)

self.assertIn("got an unexpected keyword argument 'const'", str(cm.exception))

class TestBooleanOptionalActionRequired(ParserTestCase):
"""Tests BooleanOptionalAction required"""

Expand Down
7 changes: 7 additions & 0 deletions Lib/test/test_ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,13 @@ def test_issue40614_feature_version(self):
with self.assertRaises(SyntaxError):
ast.parse('f"{x=}"', feature_version=(3, 7))

def test_constant_as_name(self):
for constant in "True", "False", "None":
expr = ast.Expression(ast.Name(constant, ast.Load()))
ast.fix_missing_locations(expr)
with self.assertRaisesRegex(ValueError, f"Name node can't be used with '{constant}' constant"):
compile(expr, "<test>", "eval")


class ASTHelpers_Test(unittest.TestCase):
maxDiff = None
Expand Down
5 changes: 5 additions & 0 deletions Lib/test/test_capi.py
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,11 @@ def test_heaptype_with_weakref(self):
self.assertEqual(ref(), inst)
self.assertEqual(inst.weakreflist, ref)

def test_heaptype_with_buffer(self):
inst = _testcapi.HeapCTypeWithBuffer()
b = bytes(inst)
self.assertEqual(b, b"1234")

def test_c_subclass_of_heap_ctype_with_tpdealloc_decrefs_once(self):
subclass_instance = _testcapi.HeapCTypeSubclass()
type_refcnt = sys.getrefcount(_testcapi.HeapCTypeSubclass)
Expand Down
2 changes: 2 additions & 0 deletions Lib/test/test_decimal.py
Original file line number Diff line number Diff line change
Expand Up @@ -5201,6 +5201,7 @@ def test_c_signal_dict(self):
DefaultContext = C.DefaultContext

InvalidOperation = C.InvalidOperation
FloatOperation = C.FloatOperation
DivisionByZero = C.DivisionByZero
Overflow = C.Overflow
Subnormal = C.Subnormal
Expand Down Expand Up @@ -5274,6 +5275,7 @@ def assertIsExclusivelySet(signal, signal_dict):
Underflow: C.DecUnderflow,
Overflow: C.DecOverflow,
DivisionByZero: C.DecDivisionByZero,
FloatOperation: C.DecFloatOperation,
InvalidOperation: C.DecIEEEInvalidOperation
}
IntCond = [
Expand Down
26 changes: 26 additions & 0 deletions Lib/test/test_importlib/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,21 @@ def setUp(self):
build_files(EggInfoFile.files, prefix=self.site_dir)


class LocalPackage:
files = {
"setup.py": """
import setuptools
setuptools.setup(name="local-pkg", version="2.0.1")
""",
}

def setUp(self):
self.fixtures = contextlib.ExitStack()
self.addCleanup(self.fixtures.close)
self.fixtures.enter_context(tempdir_as_cwd())
build_files(self.files)


def build_files(file_defs, prefix=pathlib.Path()):
"""Build a set of files/directories, as described by the

Expand Down Expand Up @@ -195,6 +210,17 @@ def build_files(file_defs, prefix=pathlib.Path()):
f.write(DALS(contents))


class FileBuilder:
def unicode_filename(self):
try:
import test.support
except ImportError:
# outside CPython, hard-code a unicode snowman
return '☃'
return test.support.FS_NONASCII or \
self.skip("File system does not support non-ascii.")


def DALS(str):
"Dedent and left-strip"
return textwrap.dedent(str).lstrip()
Expand Down
21 changes: 21 additions & 0 deletions Lib/test/test_importlib/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,3 +246,24 @@ def test_json_dump(self):
"""
with self.assertRaises(Exception):
json.dumps(self.ep)

def test_module(self):
assert self.ep.module == 'value'

def test_attr(self):
assert self.ep.attr is None


class FileSystem(
fixtures.OnSysPath, fixtures.SiteDir, fixtures.FileBuilder,
unittest.TestCase):
def test_unicode_dir_on_sys_path(self):
"""
Ensure a Unicode subdirectory of a directory on sys.path
does not crash.
"""
fixtures.build_files(
{self.unicode_filename(): {}},
prefix=self.site_dir,
)
list(distributions())
26 changes: 16 additions & 10 deletions Lib/test/test_importlib/test_zip.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@

from contextlib import ExitStack
from importlib.metadata import (
distribution, entry_points, files, PackageNotFoundError, version,
distribution, entry_points, files, PackageNotFoundError,
version, distributions,
)
from importlib.resources import path
from importlib import resources

from test.support import requires_zlib

Expand All @@ -14,15 +15,19 @@
class TestZip(unittest.TestCase):
root = 'test.test_importlib.data'

def _fixture_on_path(self, filename):
pkg_file = resources.files(self.root).joinpath(filename)
file = self.resources.enter_context(resources.as_file(pkg_file))
assert file.name.startswith('example-'), file.name
sys.path.insert(0, str(file))
self.resources.callback(sys.path.pop, 0)

def setUp(self):
# Find the path to the example-*.whl so we can add it to the front of
# sys.path, where we'll then try to find the metadata thereof.
self.resources = ExitStack()
self.addCleanup(self.resources.close)
wheel = self.resources.enter_context(
path(self.root, 'example-21.12-py3-none-any.whl'))
sys.path.insert(0, str(wheel))
self.resources.callback(sys.path.pop, 0)
self._fixture_on_path('example-21.12-py3-none-any.whl')

def test_zip_version(self):
self.assertEqual(version('example'), '21.12')
Expand All @@ -49,6 +54,10 @@ def test_files(self):
path = str(file.dist.locate_file(file))
assert '.whl/' in path, path

def test_one_distribution(self):
dists = list(distributions(path=sys.path[:1]))
assert len(dists) == 1


@requires_zlib()
class TestEgg(TestZip):
Expand All @@ -57,10 +66,7 @@ def setUp(self):
# sys.path, where we'll then try to find the metadata thereof.
self.resources = ExitStack()
self.addCleanup(self.resources.close)
egg = self.resources.enter_context(
path(self.root, 'example-21.12-py3.6.egg'))
sys.path.insert(0, str(egg))
self.resources.callback(sys.path.pop, 0)
self._fixture_on_path('example-21.12-py3.6.egg')

def test_files(self):
for file in files('example'):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Allow defining buffer slots in type specs.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Port :mod:`mmap` to multiphase initialization.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Delete unnecessary instance check in importlib.reload().
Patch by Furkan Önder.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Raise :exc:`ValueError` when validating custom AST's where the constants
``True``, ``False`` and ``None`` are used within a :class:`ast.Name` node.
Loading