Rename Method refactoring allowed for methods defined to implement container objects

Aberta
#775 0 comentários 0 reações 0 responsáveis Ver no GitHub

Mantenedores costumam responder em até 7 dias

Ninguém assumiu esta issue ainda.

Avaliação

Dificuldade
3/5
Tempo estimado
Meio dia
Facilidade para iniciantes
35/100
Tipo de issue
Bug
Clareza
Razoavelmente clara
Status de atividade
Estagnada
Stack de tecnologia
python
Domínio
devtools

Direção de pesquisa

Start by reproducing the report with the main.py and test.py from the issue, using Rename Method on StringlikeMixin.len with the new name 'text'. The open question is whether Rope should warn or refuse when a method implements a container protocol like len, and the issue does not settle that. Done means agreeing that behaviour with maintainers and then covering it with a test.

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

bug rename-refactor

Rename Method refactoring allowed for methods defined to implement container objects
It would be nice if Rope sent an alert to the user to avoid incompatible parameter type errors when using the "len()" function.

Steps to reproduce the behavior:

  1. Code before refactoring:

structure

-- main
---- main.py
-- test
---- test.py

main.py:

implements_to_string = lambda x: x

@implements_to_string
class StringlikeMixin(object):

    def __len__(self):
        return len(self._strkey())


class BaseBlob(StringlikeMixin):
    def __init__(self, text):
        self.raw = text

    def _strkey(self):
        return self.raw


class Sentence(BaseBlob):
    def __init__(self, sentence, start_index=0, end_index=None, *args, **kwargs):
        super(Sentence, self).__init__(sentence, *args, **kwargs)

test.py:

from unittest import TestCase
from main import main as tb

class SentenceTest(TestCase):

    def setUp(self):
        self.raw_sentence = 'Any place with frites and Belgian beer has my vote.'
        self.sentence = tb.Sentence(self.raw_sentence)

    def test_len(self):
        self.assertEqual(len(self.sentence), len(self.raw_sentence))

  1. Apply the Rename Method refactoring with the new name 'text' to the method 'StringlikeMixin.__len__'
Linguagem predominante
Python
Estrelas
2.2k
Forks
197
Merge médio
2d 13h
PRs com merge (30d)
5

Preparar o ambiente

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de python-rope/rope

Todas as issues de python-rope/rope

Issues semelhantes

Mais issues de Python

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.