mirror of
https://github.com/RustPython/RustPython.git
synced 2026-06-02 19:39:49 +09:00
Update operator from v3.14.2
This commit is contained in:
committed by
Jeong, YunWon
parent
37fe0cfae2
commit
ac2729511f
14
Lib/operator.py
vendored
14
Lib/operator.py
vendored
@@ -14,8 +14,8 @@ __all__ = ['abs', 'add', 'and_', 'attrgetter', 'call', 'concat', 'contains', 'co
|
||||
'delitem', 'eq', 'floordiv', 'ge', 'getitem', 'gt', 'iadd', 'iand',
|
||||
'iconcat', 'ifloordiv', 'ilshift', 'imatmul', 'imod', 'imul',
|
||||
'index', 'indexOf', 'inv', 'invert', 'ior', 'ipow', 'irshift',
|
||||
'is_', 'is_not', 'isub', 'itemgetter', 'itruediv', 'ixor', 'le',
|
||||
'length_hint', 'lshift', 'lt', 'matmul', 'methodcaller', 'mod',
|
||||
'is_', 'is_none', 'is_not', 'is_not_none', 'isub', 'itemgetter', 'itruediv',
|
||||
'ixor', 'le', 'length_hint', 'lshift', 'lt', 'matmul', 'methodcaller', 'mod',
|
||||
'mul', 'ne', 'neg', 'not_', 'or_', 'pos', 'pow', 'rshift',
|
||||
'setitem', 'sub', 'truediv', 'truth', 'xor']
|
||||
|
||||
@@ -66,6 +66,14 @@ def is_not(a, b):
|
||||
"Same as a is not b."
|
||||
return a is not b
|
||||
|
||||
def is_none(a):
|
||||
"Same as a is None."
|
||||
return a is None
|
||||
|
||||
def is_not_none(a):
|
||||
"Same as a is not None."
|
||||
return a is not None
|
||||
|
||||
# Mathematical/Bitwise Operations *********************************************#
|
||||
|
||||
def abs(a):
|
||||
@@ -415,7 +423,7 @@ try:
|
||||
except ImportError:
|
||||
pass
|
||||
else:
|
||||
from _operator import __doc__
|
||||
from _operator import __doc__ # noqa: F401
|
||||
|
||||
# All of these "__func__ = func" assignments have to happen after importing
|
||||
# from _operator to make sure they're set to the right function
|
||||
|
||||
49
Lib/test/test_operator.py
vendored
49
Lib/test/test_operator.py
vendored
@@ -347,6 +347,26 @@ class OperatorTestCase:
|
||||
self.assertFalse(operator.is_not(a, b))
|
||||
self.assertTrue(operator.is_not(a,c))
|
||||
|
||||
def test_is_none(self):
|
||||
operator = self.module
|
||||
a = 'xyzpdq'
|
||||
b = ''
|
||||
c = None
|
||||
self.assertRaises(TypeError, operator.is_none)
|
||||
self.assertFalse(operator.is_none(a))
|
||||
self.assertFalse(operator.is_none(b))
|
||||
self.assertTrue(operator.is_none(c))
|
||||
|
||||
def test_is_not_none(self):
|
||||
operator = self.module
|
||||
a = 'xyzpdq'
|
||||
b = ''
|
||||
c = None
|
||||
self.assertRaises(TypeError, operator.is_not_none)
|
||||
self.assertTrue(operator.is_not_none(a))
|
||||
self.assertTrue(operator.is_not_none(b))
|
||||
self.assertFalse(operator.is_not_none(c))
|
||||
|
||||
def test_attrgetter(self):
|
||||
operator = self.module
|
||||
class A:
|
||||
@@ -462,6 +482,8 @@ class OperatorTestCase:
|
||||
return f
|
||||
def baz(*args, **kwds):
|
||||
return kwds['name'], kwds['self']
|
||||
def return_arguments(self, *args, **kwds):
|
||||
return args, kwds
|
||||
a = A()
|
||||
f = operator.methodcaller('foo')
|
||||
self.assertRaises(IndexError, f, a)
|
||||
@@ -478,6 +500,17 @@ class OperatorTestCase:
|
||||
f = operator.methodcaller('baz', name='spam', self='eggs')
|
||||
self.assertEqual(f(a), ('spam', 'eggs'))
|
||||
|
||||
many_positional_arguments = tuple(range(10))
|
||||
many_kw_arguments = dict(zip('abcdefghij', range(10)))
|
||||
f = operator.methodcaller('return_arguments', *many_positional_arguments)
|
||||
self.assertEqual(f(a), (many_positional_arguments, {}))
|
||||
|
||||
f = operator.methodcaller('return_arguments', **many_kw_arguments)
|
||||
self.assertEqual(f(a), ((), many_kw_arguments))
|
||||
|
||||
f = operator.methodcaller('return_arguments', *many_positional_arguments, **many_kw_arguments)
|
||||
self.assertEqual(f(a), (many_positional_arguments, many_kw_arguments))
|
||||
|
||||
def test_inplace(self):
|
||||
operator = self.module
|
||||
class C(object):
|
||||
@@ -635,22 +668,20 @@ class PyOperatorTestCase(OperatorTestCase, unittest.TestCase):
|
||||
class COperatorTestCase(OperatorTestCase, unittest.TestCase):
|
||||
module = c_operator
|
||||
|
||||
# TODO: RUSTPYTHON
|
||||
@unittest.expectedFailure
|
||||
@unittest.expectedFailure # TODO: RUSTPYTHON
|
||||
def test_attrgetter_signature(self):
|
||||
super().test_attrgetter_signature()
|
||||
return super().test_attrgetter_signature()
|
||||
|
||||
# TODO: RUSTPYTHON
|
||||
@unittest.expectedFailure
|
||||
@unittest.expectedFailure # TODO: RUSTPYTHON
|
||||
def test_itemgetter_signature(self):
|
||||
super().test_itemgetter_signature()
|
||||
return super().test_itemgetter_signature()
|
||||
|
||||
# TODO: RUSTPYTHON
|
||||
@unittest.expectedFailure
|
||||
@unittest.expectedFailure # TODO: RUSTPYTHON
|
||||
def test_methodcaller_signature(self):
|
||||
super().test_methodcaller_signature()
|
||||
return super().test_methodcaller_signature()
|
||||
|
||||
|
||||
@support.thread_unsafe("swaps global operator module")
|
||||
class OperatorPickleTestCase:
|
||||
def copy(self, obj, proto):
|
||||
with support.swap_item(sys.modules, 'operator', self.module):
|
||||
|
||||
Reference in New Issue
Block a user