Rename Method refactoring allowed for methods designed for numeric type emulation
Maintainer antworten meist innerhalb von 7 Tagen
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Anfängerfreundlichkeit
- 35/100
Rechercherichtung
The reproduction uses BaseBlob.__add__ in blob.py with TextBlob and test_add in test.py, and the Rename Method refactoring is the entry point to check. Reproduce the rename of __add__ to 'extractor' and confirm that blob1 + blob2 then fails. Done means the refactoring either warns or refuses when the target is an operator-emulation dunder method, which needs a decision on the intended behaviour first.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
Rename Method refactoring is allowed to change the name of methods designed to emulate numeric operations.
It would be nice if Rope sent an alert, as this transformation may cause type errors regarding unsupported operands.
Steps to reproduce the behavior:
- Code before refactoring:
structure
-- main
---- blob.py
-- test
---- test.py
blob.py:
class BaseBlob(object):
def __init__(self, text):
self.raw = text
def _cmpkey(self):
return self.raw
def _compare(self, other, method):
try:
return method(self._cmpkey(), other._cmpkey())
except (AttributeError, TypeError):
return NotImplemented
def __eq__(self, other):
return self._compare(other, lambda s, o: s == o)
def __add__(self, other):
if isinstance(other, (str, bytes)):
return self.__class__(self.raw + other)
elif isinstance(other, BaseBlob):
return self.__class__(self.raw + other.raw)
else:
raise TypeError('Operands must be either strings or {0} objects'
.format(self.__class__.__name__))
class TextBlob(BaseBlob):
pass
test.py:
from unittest import TestCase, main
from main import blob as tb
class TextBlobTest(TestCase):
def test_add(self):
blob1 = tb.TextBlob('Hello, world! ')
blob2 = tb.TextBlob('Hola mundo!')
self.assertEqual(blob1 + blob2, tb.TextBlob('Hello, world! Hola mundo!'))
self.assertEqual(blob1 + 'Hola mundo!', tb.TextBlob('Hello, world! Hola mundo!'))
self.assertEqual(blob1 + blob2 + ' Goodbye!', tb.TextBlob('Hello, world! Hola mundo! Goodbye!'))
self.assertRaises(TypeError, blob1.__add__, ['hello'])
- Apply the Rename Method refactoring with the new name 'extractor' to 'BaseBlob.__add__'
- Vorherrschende Sprache
- Python
- Sterne
- 2.2k
- Forks
- 197
- Ø Merge
- 2 T. 13 Std.
- Gemergte PRs (30 T.)
- 5
Entwicklungsumgebung
- Kein Dockerfile und keine Docker-Compose-Datei
- Hat eine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus python-rope/rope
-
Schwierigkeit 1/5 1-3 Stunden Anfängerfreundlichkeit 88/100
python-rope/rope#927 ·
Maintainer antworten meist innerhalb von 7 Tagen
-
Extract raises IndexError or ModuleSyntaxError instead of RefactoringError for an empty or whitespace-only regionEvtl. vergeben @aliassar hat das heute übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
python-rope/rope#926 ·
Maintainer antworten meist innerhalb von 7 Tagen
-
simplify.real_code blanks t-strings, so renames inside them edit the wrong offsetEvtl. vergeben @sean0407 hat das vor 10 Tagen übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 83/100
python-rope/rope#913 ·
Maintainer antworten meist innerhalb von 7 Tagen
-
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 30/100
python-rope/rope#925 ·
Maintainer antworten meist innerhalb von 7 Tagen
-
Extract method/variable and introduce parameter don't check whether the new name is already in useOffen
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 62/100
python-rope/rope#924 ·
Maintainer antworten meist innerhalb von 7 Tagen
Alle Issues in python-rope/rope
Ähnliche Issues
-
Paraxial.trace returns NaN for an object at infinity when the entrance pupil is at the first surfaceOffen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 75/100
Maintainer antworten meist innerhalb von 1 Tag
-
enhancement ios launcher
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 70/100
Maintainer antworten meist innerhalb von 1 Tag
-
Substrait consumer doesn't recognise `shift_left` / `shift_right` from functions_arithmetic.yamlOffenbug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 76/100
apache/datafusion#27059 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 85/100
loteran/Arctis-Sound-Manager#368 ·
Maintainer antworten meist innerhalb von 1 Tag
-
feed submission
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 65/100
MobilityData/mobility-database-catalogs#1787 ·
Maintainer antworten meist innerhalb von 2 Tagen