Rename Method refactoring allowed for methods designed for numeric type emulation
I maintainer di solito rispondono entro 7 giorni
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 35/100
Direzione di ricerca
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.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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__'
- Lingua principale
- Python
- Stelle
- 2.2k
- Fork
- 197
- Merge medio
- 2g 13h
- PR unite (30g)
- 5
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di python-rope/rope
-
Difficoltà 1/5 1-3 ore Idoneità per principianti 88/100
python-rope/rope#927 ·
I maintainer di solito rispondono entro 7 giorni
-
Extract raises IndexError or ModuleSyntaxError instead of RefactoringError for an empty or whitespace-only regionForse già presa @aliassar l’ha presa 1 giorno fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
python-rope/rope#926 ·
I maintainer di solito rispondono entro 7 giorni
-
simplify.real_code blanks t-strings, so renames inside them edit the wrong offsetForse già presa @sean0407 l’ha presa 11 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 83/100
python-rope/rope#913 ·
I maintainer di solito rispondono entro 7 giorni
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 30/100
python-rope/rope#925 ·
I maintainer di solito rispondono entro 7 giorni
-
Extract method/variable and introduce parameter don't check whether the new name is already in useForse già presa @aliassar l’ha presa oggi. Aperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 62/100
python-rope/rope#924 · 1 commento ·
I maintainer di solito rispondono entro 7 giorni
Tutte le issue di python-rope/rope
Issue simili
-
flow-measurement measurement
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 76/100
MichaelYcJo/SpecSeal#1366 ·
-
bug c/evals c/ui size:L
Difficoltà 2/5 1-3 ore Idoneità per principianti 66/100
Arize-ai/phoenix#17633 · 2 commenti · 1 reazione ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
TransformerLensOrg/TransformerLens#1980 ·
I maintainer di solito rispondono entro 1 giorno
-
Module: Solr Needs: Lead Needs: Triage Theme: Search Type: Bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
internetarchive/openlibrary#14284 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 69/100
SpaceCowMedia/commander-spellbook-backend#1292 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno