Skip to content

Commit

Permalink
Merge branch 'main' into fieldrepr
Browse files Browse the repository at this point in the history
* main:
  pythonGH-100288: Remove LOAD_ATTR_METHOD_WITH_DICT instruction. (pythonGH-100753)
  pythonGH-100766: Note that locale.LC_MESSAGES is not universal (pythonGH-100702)
  Drop myself from pathlib maintenance (python#100757)
  pythongh-100739: Respect mock spec when checking for unsafe prefixes (python#100740)
  • Loading branch information
carljm committed Jan 5, 2023
2 parents 7241045 + f20c553 commit 60aa562
Show file tree
Hide file tree
Showing 13 changed files with 62 additions and 100 deletions.
5 changes: 1 addition & 4 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ Python/traceback.c @iritkatriel
# bytecode.
**/*import*.c @brettcannon @encukou @ericsnowcurrently @ncoghlan @warsaw
**/*import*.py @brettcannon @encukou @ericsnowcurrently @ncoghlan @warsaw
**/*importlib/resources/* @jaraco @warsaw @brettcannon @FFY00
**/*importlib/resources/* @jaraco @warsaw @FFY00
**/importlib/metadata/* @jaraco @warsaw

# Dates and times
Expand Down Expand Up @@ -152,8 +152,5 @@ Lib/ast.py @isidentical
/Mac/ @python/macos-team
**/*osx_support* @python/macos-team

# pathlib
**/*pathlib* @brettcannon

# zipfile.Path
**/*zipfile/*_path.py @jaraco
3 changes: 3 additions & 0 deletions Doc/library/locale.rst
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,9 @@ The :mod:`locale` module defines the following exception and functions:
system, like those returned by :func:`os.strerror` might be affected by this
category.

This value may not be available on operating systems not conforming to the
POSIX standard, most notably Windows.


.. data:: LC_NUMERIC

Expand Down
20 changes: 10 additions & 10 deletions Include/internal/pycore_opcode.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 16 additions & 17 deletions Include/opcode.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Lib/opcode.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,6 @@ def pseudo_op(name, op, real_ops):
# These will always push [unbound method, self] onto the stack.
"LOAD_ATTR_METHOD_LAZY_DICT",
"LOAD_ATTR_METHOD_NO_DICT",
"LOAD_ATTR_METHOD_WITH_DICT",
"LOAD_ATTR_METHOD_WITH_VALUES",
],
"LOAD_CONST": [
Expand Down
16 changes: 16 additions & 0 deletions Lib/test/test_unittest/testmock/testmock.py
Original file line number Diff line number Diff line change
Expand Up @@ -1652,6 +1652,22 @@ def test_mock_unsafe(self):
m.aseert_foo_call()
m.assrt_foo_call()

# gh-100739
def test_mock_safe_with_spec(self):
class Foo(object):
def assert_bar(self):
pass

def assertSome(self):
pass

m = Mock(spec=Foo)
m.assert_bar()
m.assertSome()

m.assert_bar.assert_called_once()
m.assertSome.assert_called_once()

#Issue21262
def test_assert_not_called(self):
m = Mock()
Expand Down
2 changes: 1 addition & 1 deletion Lib/unittest/mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,7 @@ def __getattr__(self, name):
raise AttributeError("Mock object has no attribute %r" % name)
elif _is_magic(name):
raise AttributeError(name)
if not self._mock_unsafe:
if not self._mock_unsafe and (not self._mock_methods or name not in self._mock_methods):
if name.startswith(('assert', 'assret', 'asert', 'aseert', 'assrt')):
raise AttributeError(
f"{name!r} is not a valid assertion. Use a spec "
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Remove the LOAD_ATTR_METHOD_WITH_DICT specialized instruction. Stats show it
is not useful.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix ``unittest.mock.Mock`` not respecting the spec for attribute names prefixed with ``assert``.
29 changes: 1 addition & 28 deletions Python/bytecodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -2605,33 +2605,6 @@ dummy_func(
JUMPBY(INLINE_CACHE_ENTRIES_LOAD_ATTR);
}

// error: LOAD_ATTR has irregular stack effect
inst(LOAD_ATTR_METHOD_WITH_DICT) {
/* Can be either a managed dict, or a tp_dictoffset offset.*/
assert(cframe.use_tracing == 0);
PyObject *self = TOP();
PyTypeObject *self_cls = Py_TYPE(self);
_PyLoadMethodCache *cache = (_PyLoadMethodCache *)next_instr;

DEOPT_IF(self_cls->tp_version_tag != read_u32(cache->type_version),
LOAD_ATTR);
/* Treat index as a signed 16 bit value */
Py_ssize_t dictoffset = self_cls->tp_dictoffset;
assert(dictoffset > 0);
PyDictObject **dictptr = (PyDictObject**)(((char *)self)+dictoffset);
PyDictObject *dict = *dictptr;
DEOPT_IF(dict == NULL, LOAD_ATTR);
DEOPT_IF(dict->ma_keys->dk_version != read_u32(cache->keys_version),
LOAD_ATTR);
STAT_INC(LOAD_ATTR, hit);
PyObject *res = read_obj(cache->descr);
assert(res != NULL);
assert(_PyType_HasFeature(Py_TYPE(res), Py_TPFLAGS_METHOD_DESCRIPTOR));
SET_TOP(Py_NewRef(res));
PUSH(self);
JUMPBY(INLINE_CACHE_ENTRIES_LOAD_ATTR);
}

// error: LOAD_ATTR has irregular stack effect
inst(LOAD_ATTR_METHOD_NO_DICT) {
assert(cframe.use_tracing == 0);
Expand Down Expand Up @@ -3517,7 +3490,7 @@ family(load_attr) = {
LOAD_ATTR, LOAD_ATTR_CLASS,
LOAD_ATTR_GETATTRIBUTE_OVERRIDDEN, LOAD_ATTR_INSTANCE_VALUE, LOAD_ATTR_MODULE,
LOAD_ATTR_PROPERTY, LOAD_ATTR_SLOT, LOAD_ATTR_WITH_HINT,
LOAD_ATTR_METHOD_LAZY_DICT, LOAD_ATTR_METHOD_NO_DICT, LOAD_ATTR_METHOD_WITH_DICT,
LOAD_ATTR_METHOD_LAZY_DICT, LOAD_ATTR_METHOD_NO_DICT,
LOAD_ATTR_METHOD_WITH_VALUES };
family(load_global) = {
LOAD_GLOBAL, LOAD_GLOBAL_BUILTIN,
Expand Down
27 changes: 0 additions & 27 deletions Python/generated_cases.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 9 additions & 9 deletions Python/opcode_targets.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions Python/specialize.c
Original file line number Diff line number Diff line change
Expand Up @@ -1091,9 +1091,8 @@ PyObject *descr, DescriptorClassification kind)
SPECIALIZATION_FAIL(LOAD_ATTR, SPEC_FAIL_ATTR_HAS_MANAGED_DICT);
goto fail;
case OFFSET_DICT:
assert(owner_cls->tp_dictoffset > 0 && owner_cls->tp_dictoffset <= INT16_MAX);
_py_set_opcode(instr, LOAD_ATTR_METHOD_WITH_DICT);
break;
SPECIALIZATION_FAIL(LOAD_ATTR, SPEC_FAIL_ATTR_NOT_MANAGED_DICT);
goto fail;
case LAZY_DICT:
assert(owner_cls->tp_dictoffset > 0 && owner_cls->tp_dictoffset <= INT16_MAX);
_py_set_opcode(instr, LOAD_ATTR_METHOD_LAZY_DICT);
Expand Down

0 comments on commit 60aa562

Please sign in to comment.