Issue #24379: Revert the operator.subscript patch (dccc4e63aef5) pen… · python/cpython@a1fc949

GitHub

Original file line numberDiff line numberDiff line change@@ -333,21 +333,6 @@ expect a function argument.

333333[('orange', 1), ('banana', 2), ('apple', 3), ('pear', 5)]

334334335335336-.. data:: subscript

337-338- A helper to turn subscript notation into indexing objects. This can be

339- used to create item access patterns ahead of time to pass them into

340- various subscriptable objects.

341-342- For example:

343-344- * ``subscript[5] == 5``

345- * ``subscript[3:7:2] == slice(3, 7, 2)``

346- * ``subscript[5, 8] == (5, 8)``

347-348- .. versionadded:: 3.6

349-350-351336.. function:: methodcaller(name[, args...])

352337353338 Return a callable object that calls the method *name* on its operand. If

Original file line numberDiff line numberDiff line change@@ -104,14 +104,6 @@ directives ``%G``, ``%u`` and ``%V``.

104104(Contributed by Ashley Anderson in :issue:`12006`.)

105105106106107-operator

108---------

109-110-New object :data:`operator.subscript` makes it easier to create complex

111-indexers. For example: ``subscript[0:10:2] == slice(0, 10, 2)``

112-(Contributed by Joe Jevnik in :issue:`24379`.)

113-114-115107pickle

116108------

117109Original file line numberDiff line numberDiff line change@@ -17,7 +17,7 @@

1717'is_', 'is_not', 'isub', 'itemgetter', 'itruediv', 'ixor', 'le',

1818'length_hint', 'lshift', 'lt', 'matmul', 'methodcaller', 'mod',

1919'mul', 'ne', 'neg', 'not_', 'or_', 'pos', 'pow', 'rshift',

20-'setitem', 'sub', 'subscript', 'truediv', 'truth', 'xor']

20+'setitem', 'sub', 'truediv', 'truth', 'xor']

21212222frombuiltinsimportabsas_abs

2323@@ -408,32 +408,6 @@ def ixor(a, b):

408408returna

409409410410411-@object.__new__# create a singleton instance

412-classsubscript:

413-"""

414- A helper to turn subscript notation into indexing objects. This can be

415- used to create item access patterns ahead of time to pass them into

416- various subscriptable objects.

417-418- For example:

419- subscript[5] == 5

420- subscript[3:7:2] == slice(3, 7, 2)

421- subscript[5, 8] == (5, 8)

422- """

423-__slots__= ()

424-425-def__new__(cls):

426-raiseTypeError("cannot create '{}' instances".format(cls.__name__))

427-428-@staticmethod

429-def__getitem__(key):

430-returnkey

431-432-@staticmethod

433-def__reduce__():

434-return'subscript'

435-436-437411try:

438412from_operatorimport*

439413exceptImportError:

Original file line numberDiff line numberDiff line change@@ -596,38 +596,5 @@ class CCOperatorPickleTestCase(OperatorPickleTestCase, unittest.TestCase):

596596module2=c_operator

597597598598599-classSubscriptTestCase:

600-deftest_subscript(self):

601-subscript=self.module.subscript

602-self.assertIsNone(subscript[None])

603-self.assertEqual(subscript[0], 0)

604-self.assertEqual(subscript[0:1:2], slice(0, 1, 2))

605-self.assertEqual(

606-subscript[0, ..., :2, ...],

607- (0, Ellipsis, slice(2), Ellipsis),

608- )

609-610-deftest_pickle(self):

611-fromoperatorimportsubscript

612-forprotoinrange(pickle.HIGHEST_PROTOCOL+1):

613-withself.subTest(proto=proto):

614-self.assertIs(

615-pickle.loads(pickle.dumps(subscript, proto)),

616-subscript,

617- )

618-619-deftest_singleton(self):

620-withself.assertRaises(TypeError):

621-type(self.module.subscript)()

622-623-deftest_immutable(self):

624-withself.assertRaises(AttributeError):

625-self.module.subscript.attr=None

626-627-628-classPySubscriptTestCase(SubscriptTestCase, PyOperatorTestCase):

629-pass

630-631-632599if__name__=="__main__":

633600unittest.main()