mirror of
https://github.com/python/cpython.git
synced 2025-07-07 11:25:30 +00:00
gh-136203: Improve TypeError
msg when comparing two MappingProxyType
s (#136204)
Some checks are pending
Tests / WASI (push) Blocked by required conditions
Tests / Hypothesis tests on Ubuntu (push) Blocked by required conditions
Tests / Address sanitizer (push) Blocked by required conditions
Tests / (push) Blocked by required conditions
Tests / Undefined behavior sanitizer (push) Blocked by required conditions
Tests / Cross build Linux (push) Blocked by required conditions
Tests / Windows MSI (push) Blocked by required conditions
Tests / Change detection (push) Waiting to run
Tests / Docs (push) Blocked by required conditions
Tests / Check if Autoconf files are up to date (push) Blocked by required conditions
Tests / Check if generated files are up to date (push) Blocked by required conditions
Tests / CIFuzz (push) Blocked by required conditions
Tests / All required checks pass (push) Blocked by required conditions
Lint / lint (push) Waiting to run
Tests / Ubuntu SSL tests with OpenSSL (push) Blocked by required conditions
mypy / Run mypy on Lib/_pyrepl (push) Waiting to run
mypy / Run mypy on Lib/test/libregrtest (push) Waiting to run
mypy / Run mypy on Lib/tomllib (push) Waiting to run
mypy / Run mypy on Tools/build (push) Waiting to run
mypy / Run mypy on Tools/cases_generator (push) Waiting to run
mypy / Run mypy on Tools/clinic (push) Waiting to run
mypy / Run mypy on Tools/jit (push) Waiting to run
mypy / Run mypy on Tools/peg_generator (push) Waiting to run
Some checks are pending
Tests / WASI (push) Blocked by required conditions
Tests / Hypothesis tests on Ubuntu (push) Blocked by required conditions
Tests / Address sanitizer (push) Blocked by required conditions
Tests / (push) Blocked by required conditions
Tests / Undefined behavior sanitizer (push) Blocked by required conditions
Tests / Cross build Linux (push) Blocked by required conditions
Tests / Windows MSI (push) Blocked by required conditions
Tests / Change detection (push) Waiting to run
Tests / Docs (push) Blocked by required conditions
Tests / Check if Autoconf files are up to date (push) Blocked by required conditions
Tests / Check if generated files are up to date (push) Blocked by required conditions
Tests / CIFuzz (push) Blocked by required conditions
Tests / All required checks pass (push) Blocked by required conditions
Lint / lint (push) Waiting to run
Tests / Ubuntu SSL tests with OpenSSL (push) Blocked by required conditions
mypy / Run mypy on Lib/_pyrepl (push) Waiting to run
mypy / Run mypy on Lib/test/libregrtest (push) Waiting to run
mypy / Run mypy on Lib/tomllib (push) Waiting to run
mypy / Run mypy on Tools/build (push) Waiting to run
mypy / Run mypy on Tools/cases_generator (push) Waiting to run
mypy / Run mypy on Tools/clinic (push) Waiting to run
mypy / Run mypy on Tools/jit (push) Waiting to run
mypy / Run mypy on Tools/peg_generator (push) Waiting to run
Co-authored-by: Victor Stinner <vstinner@python.org>
This commit is contained in:
parent
fa43a1e0f8
commit
41a9b46ad4
3 changed files with 27 additions and 1 deletions
|
@ -1376,6 +1376,27 @@ class MappingProxyTests(unittest.TestCase):
|
|||
view = self.mappingproxy(mapping)
|
||||
self.assertEqual(hash(view), hash(mapping))
|
||||
|
||||
def test_richcompare(self):
|
||||
mp1 = self.mappingproxy({'a': 1})
|
||||
mp1_2 = self.mappingproxy({'a': 1})
|
||||
mp2 = self.mappingproxy({'a': 2})
|
||||
|
||||
self.assertTrue(mp1 == mp1_2)
|
||||
self.assertFalse(mp1 != mp1_2)
|
||||
self.assertFalse(mp1 == mp2)
|
||||
self.assertTrue(mp1 != mp2)
|
||||
|
||||
msg = "not supported between instances of 'mappingproxy' and 'mappingproxy'"
|
||||
|
||||
with self.assertRaisesRegex(TypeError, msg):
|
||||
mp1 > mp2
|
||||
with self.assertRaisesRegex(TypeError, msg):
|
||||
mp1 < mp1_2
|
||||
with self.assertRaisesRegex(TypeError, msg):
|
||||
mp2 >= mp2
|
||||
with self.assertRaisesRegex(TypeError, msg):
|
||||
mp1_2 <= mp1
|
||||
|
||||
|
||||
class ClassCreationTests(unittest.TestCase):
|
||||
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
Improve :exc:`TypeError` error message, when richcomparing two
|
||||
:class:`types.MappingProxyType` objects.
|
|
@ -1233,7 +1233,10 @@ static PyObject *
|
|||
mappingproxy_richcompare(PyObject *self, PyObject *w, int op)
|
||||
{
|
||||
mappingproxyobject *v = (mappingproxyobject *)self;
|
||||
return PyObject_RichCompare(v->mapping, w, op);
|
||||
if (op == Py_EQ || op == Py_NE) {
|
||||
return PyObject_RichCompare(v->mapping, w, op);
|
||||
}
|
||||
Py_RETURN_NOTIMPLEMENTED;
|
||||
}
|
||||
|
||||
static int
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue