Rename Method refactoring allowed for methods defined to implement container objects

未關閉
#775 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 7 天內回覆

還沒有人認領這個 Issue。

評估

難度
3/5
預估耗時
半天
新手友好度
35/100
Issue 類型
缺陷
描述清晰度
基本清楚
活躍度
停滯
技術堆疊
python
領域
devtools

研究方向

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.

由索引模型根據 Issue 內容生成。

描述

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__'
主要語言
Python
星號
2.2k
分支
197
平均合併
2 天 13 小時
30 天內合併 PR
5

環境準備

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

python-rope/rope 的其他 Issue

查看 python-rope/rope 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。