GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Update operator from 3.13.5 by ShaharNaveh · Pull Request #5935 · RustPython/RustPython

Update operator from 3.13.5 #5935

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Sign up for GitHub

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
youknowone merged 5 commits into RustPython:main from ShaharNaveh:update-operator
Jul 11, 2025

Uh oh!

There was an error while loading. Please reload this page.

Merged

Update operator from 3.13.5 #5935

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
5 commits
Select commit Hold shift + click to select a range
a1fb196
Update operator from 3.13.5
ShaharNaveh Jul 10, 2025
9f7c299
Fix some of failing tests
ShaharNaveh Jul 10, 2025
770a000
Skip failing tests
ShaharNaveh Jul 11, 2025
a3ae24e
Override test methods instead of skipping them
ShaharNaveh Jul 11, 2025
402dbec
fmt
ShaharNaveh Jul 11, 2025
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view

There are no files selected for viewing

10 changes: 5 additions & 5 deletions 10 Lib/operator.py
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ class attrgetter:
"""
__slots__ = ('_attrs', '_call')

def __init__(self, attr, *attrs):
def __init__(self, attr, /, *attrs):
if not attrs:
if not isinstance(attr, str):
raise TypeError('attribute name must be a string')
Expand All @@ -257,7 +257,7 @@ def func(obj):
return tuple(getter(obj) for getter in getters)
self._call = func

def __call__(self, obj):
def __call__(self, obj, /):
return self._call(obj)

def __repr__(self):
Expand All @@ -276,7 +276,7 @@ class itemgetter:
"""
__slots__ = ('_items', '_call')

def __init__(self, item, *items):
def __init__(self, item, /, *items):
if not items:
self._items = (item,)
def func(obj):
Expand All @@ -288,7 +288,7 @@ def func(obj):
return tuple(obj[i] for i in items)
self._call = func

def __call__(self, obj):
def __call__(self, obj, /):
return self._call(obj)

def __repr__(self):
Expand All @@ -315,7 +315,7 @@ def __init__(self, name, /, *args, **kwargs):
self._args = args
self._kwargs = kwargs

def __call__(self, obj):
def __call__(self, obj, /):
return getattr(obj, self._name)(*self._args, **self._kwargs)

def __repr__(self):
Expand Down
88 changes: 88 additions & 0 deletions 88 Lib/test/test_operator.py
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import unittest
import inspect
import pickle
import sys
from decimal import Decimal
from fractions import Fraction

from test import support
from test.support import import_helper
Expand Down Expand Up @@ -508,6 +511,44 @@ def __getitem__(self, other): return 5 # so that C is a sequence
self.assertEqual(operator.ixor (c, 5), "ixor")
self.assertEqual(operator.iconcat (c, c), "iadd")

def test_iconcat_without_getitem(self):
operator = self.module

msg = "'int' object can't be concatenated"
with self.assertRaisesRegex(TypeError, msg):
operator.iconcat(1, 0.5)

def test_index(self):
operator = self.module
class X:
def __index__(self):
return 1

self.assertEqual(operator.index(X()), 1)
self.assertEqual(operator.index(0), 0)
self.assertEqual(operator.index(1), 1)
self.assertEqual(operator.index(2), 2)
with self.assertRaises((AttributeError, TypeError)):
operator.index(1.5)
with self.assertRaises((AttributeError, TypeError)):
operator.index(Fraction(3, 7))
with self.assertRaises((AttributeError, TypeError)):
operator.index(Decimal(1))
with self.assertRaises((AttributeError, TypeError)):
operator.index(None)

def test_not_(self):
operator = self.module
class C:
def __bool__(self):
raise SyntaxError
self.assertRaises(TypeError, operator.not_)
self.assertRaises(SyntaxError, operator.not_, C())
self.assertFalse(operator.not_(5))
self.assertFalse(operator.not_([0]))
self.assertTrue(operator.not_(0))
self.assertTrue(operator.not_([]))

def test_length_hint(self):
operator = self.module
class X(object):
Expand All @@ -533,6 +574,13 @@ def __length_hint__(self):
with self.assertRaises(LookupError):
operator.length_hint(X(LookupError))

class Y: pass

msg = "'str' object cannot be interpreted as an integer"
with self.assertRaisesRegex(TypeError, msg):
operator.length_hint(X(2), "abc")
self.assertEqual(operator.length_hint(Y(), 10), 10)

def test_call(self):
operator = self.module

Expand All @@ -555,13 +603,53 @@ def test_dunder_is_original(self):
if dunder:
self.assertIs(dunder, orig)

@support.requires_docstrings
def test_attrgetter_signature(self):
Comment thread

@ShaharNaveh ShaharNaveh Jul 10, 2025

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have tried to mark those signature tests with unittest.expectedFailure but then the test fails on "UNEXPECTED SUCCESS", very strange.

I have tried to mess with defining __text_signature__ but I'm guessing that I'm doing something wrong because it completely ignores it. I would appreciate any suggestion that you have:)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@youknowone youknowone Jul 10, 2025

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it is a base class of multiple other tests

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
operator = self.module
sig = inspect.signature(operator.attrgetter)
self.assertEqual(str(sig), '(attr, /, *attrs)')
sig = inspect.signature(operator.attrgetter('x', 'z', 'y'))
self.assertEqual(str(sig), '(obj, /)')

@support.requires_docstrings
def test_itemgetter_signature(self):
operator = self.module
sig = inspect.signature(operator.itemgetter)
self.assertEqual(str(sig), '(item, /, *items)')
sig = inspect.signature(operator.itemgetter(2, 3, 5))
self.assertEqual(str(sig), '(obj, /)')

@support.requires_docstrings
def test_methodcaller_signature(self):
operator = self.module
sig = inspect.signature(operator.methodcaller)
self.assertEqual(str(sig), '(name, /, *args, **kwargs)')
sig = inspect.signature(operator.methodcaller('foo', 2, y=3))
self.assertEqual(str(sig), '(obj, /)')


class PyOperatorTestCase(OperatorTestCase, unittest.TestCase):
module = py_operator

@unittest.skipUnless(c_operator, 'requires _operator')
class COperatorTestCase(OperatorTestCase, unittest.TestCase):
module = c_operator

# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_attrgetter_signature(self):
super().test_attrgetter_signature()

# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_itemgetter_signature(self):
super().test_itemgetter_signature()

# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_methodcaller_signature(self):
super().test_methodcaller_signature()


class OperatorPickleTestCase:
def copy(self, obj, proto):
Expand Down
9 changes: 5 additions & 4 deletions 9 vm/src/stdlib/operator.rs
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ mod _operator {
.map(|v| {
if !v.fast_isinstance(vm.ctx.types.int_type) {
return Err(vm.new_type_error(format!(
"'{}' type cannot be interpreted as an integer",
"'{}' object cannot be interpreted as an integer",
v.class().name()
)));
}
Expand Down Expand Up @@ -253,9 +253,10 @@ mod _operator {
if !a.class().has_attr(identifier!(vm, __getitem__))
|| a.fast_isinstance(vm.ctx.types.dict_type)
{
return Err(
vm.new_type_error(format!("{} object can't be concatenated", a.class().name()))
);
return Err(vm.new_type_error(format!(
"'{}' object can't be concatenated",
a.class().name()
)));
}
vm._iadd(&a, &b)
}
Expand Down
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.