Skip to content

Commit ac27295

Browse files
CPython Developersyouknowone
authored andcommitted
Update operator from v3.14.2
1 parent 37fe0cf commit ac27295

2 files changed

Lines changed: 51 additions & 12 deletions

File tree

Lib/operator.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
'delitem', 'eq', 'floordiv', 'ge', 'getitem', 'gt', 'iadd', 'iand',
1515
'iconcat', 'ifloordiv', 'ilshift', 'imatmul', 'imod', 'imul',
1616
'index', 'indexOf', 'inv', 'invert', 'ior', 'ipow', 'irshift',
17-
'is_', 'is_not', 'isub', 'itemgetter', 'itruediv', 'ixor', 'le',
18-
'length_hint', 'lshift', 'lt', 'matmul', 'methodcaller', 'mod',
17+
'is_', 'is_none', 'is_not', 'is_not_none', 'isub', 'itemgetter', 'itruediv',
18+
'ixor', 'le', 'length_hint', 'lshift', 'lt', 'matmul', 'methodcaller', 'mod',
1919
'mul', 'ne', 'neg', 'not_', 'or_', 'pos', 'pow', 'rshift',
2020
'setitem', 'sub', 'truediv', 'truth', 'xor']
2121

@@ -66,6 +66,14 @@ def is_not(a, b):
6666
"Same as a is not b."
6767
return a is not b
6868

69+
def is_none(a):
70+
"Same as a is None."
71+
return a is None
72+
73+
def is_not_none(a):
74+
"Same as a is not None."
75+
return a is not None
76+
6977
# Mathematical/Bitwise Operations *********************************************#
7078

7179
def abs(a):
@@ -415,7 +423,7 @@ def ixor(a, b):
415423
except ImportError:
416424
pass
417425
else:
418-
from _operator import __doc__
426+
from _operator import __doc__ # noqa: F401
419427

420428
# All of these "__func__ = func" assignments have to happen after importing
421429
# from _operator to make sure they're set to the right function

Lib/test/test_operator.py

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,26 @@ def test_is_not(self):
347347
self.assertFalse(operator.is_not(a, b))
348348
self.assertTrue(operator.is_not(a,c))
349349

350+
def test_is_none(self):
351+
operator = self.module
352+
a = 'xyzpdq'
353+
b = ''
354+
c = None
355+
self.assertRaises(TypeError, operator.is_none)
356+
self.assertFalse(operator.is_none(a))
357+
self.assertFalse(operator.is_none(b))
358+
self.assertTrue(operator.is_none(c))
359+
360+
def test_is_not_none(self):
361+
operator = self.module
362+
a = 'xyzpdq'
363+
b = ''
364+
c = None
365+
self.assertRaises(TypeError, operator.is_not_none)
366+
self.assertTrue(operator.is_not_none(a))
367+
self.assertTrue(operator.is_not_none(b))
368+
self.assertFalse(operator.is_not_none(c))
369+
350370
def test_attrgetter(self):
351371
operator = self.module
352372
class A:
@@ -462,6 +482,8 @@ def bar(self, f=42):
462482
return f
463483
def baz(*args, **kwds):
464484
return kwds['name'], kwds['self']
485+
def return_arguments(self, *args, **kwds):
486+
return args, kwds
465487
a = A()
466488
f = operator.methodcaller('foo')
467489
self.assertRaises(IndexError, f, a)
@@ -478,6 +500,17 @@ def baz(*args, **kwds):
478500
f = operator.methodcaller('baz', name='spam', self='eggs')
479501
self.assertEqual(f(a), ('spam', 'eggs'))
480502

503+
many_positional_arguments = tuple(range(10))
504+
many_kw_arguments = dict(zip('abcdefghij', range(10)))
505+
f = operator.methodcaller('return_arguments', *many_positional_arguments)
506+
self.assertEqual(f(a), (many_positional_arguments, {}))
507+
508+
f = operator.methodcaller('return_arguments', **many_kw_arguments)
509+
self.assertEqual(f(a), ((), many_kw_arguments))
510+
511+
f = operator.methodcaller('return_arguments', *many_positional_arguments, **many_kw_arguments)
512+
self.assertEqual(f(a), (many_positional_arguments, many_kw_arguments))
513+
481514
def test_inplace(self):
482515
operator = self.module
483516
class C(object):
@@ -635,22 +668,20 @@ class PyOperatorTestCase(OperatorTestCase, unittest.TestCase):
635668
class COperatorTestCase(OperatorTestCase, unittest.TestCase):
636669
module = c_operator
637670

638-
# TODO: RUSTPYTHON
639-
@unittest.expectedFailure
671+
@unittest.expectedFailure # TODO: RUSTPYTHON
640672
def test_attrgetter_signature(self):
641-
super().test_attrgetter_signature()
673+
return super().test_attrgetter_signature()
642674

643-
# TODO: RUSTPYTHON
644-
@unittest.expectedFailure
675+
@unittest.expectedFailure # TODO: RUSTPYTHON
645676
def test_itemgetter_signature(self):
646-
super().test_itemgetter_signature()
677+
return super().test_itemgetter_signature()
647678

648-
# TODO: RUSTPYTHON
649-
@unittest.expectedFailure
679+
@unittest.expectedFailure # TODO: RUSTPYTHON
650680
def test_methodcaller_signature(self):
651-
super().test_methodcaller_signature()
681+
return super().test_methodcaller_signature()
652682

653683

684+
@support.thread_unsafe("swaps global operator module")
654685
class OperatorPickleTestCase:
655686
def copy(self, obj, proto):
656687
with support.swap_item(sys.modules, 'operator', self.module):

0 commit comments

Comments
 (0)