python-rope / rope

a python refactoring library

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Rename Method refactoring allows you to rename a method to a name with an 'internal use' indicator

researcher175 opened this issue · comments

Rename Method refactoring allows the use of the name of an 'internal field' to rename a public method.
According to PEP 8, special formats starting with underscores are recognized as 'internal use' indicators, and import formats ignore those names
This can cause errors related to undefined attributes or incompatible types.
It would be nice if Rope sent an alert to users in this operation type

  1. Steps to reproduce the behavior:
import csv
from collections import OrderedDict

DEFAULT_ENCODING = 'utf-8'

class BaseFormat(object):
    def __init__(self, fp, **kwargs):
        pass

    def to_iterable(self):
        raise NotImplementedError('Must implement a "to_iterable" method.')

    @classmethod
    def detect(cls, stream):
        raise NotImplementedError('Must implement a "detect" class method.')

class CSV(BaseFormat):
    delimiter = ","

    def __init__(self, fp, **kwargs):
        BaseFormat.__init__(self, fp, **kwargs)
        reader = csv.reader(fp, delimiter=self.delimiter)
        self.data = [row for row in reader]

    def to_iterable(self):
        return self.data

    @classmethod
    def detect(cls, stream):
        return False


_registry = OrderedDict([
    ('csv', CSV),
])


def detect(fp, max_read=1024):
    for Format in _registry.values():
        if Format.detect(fp.read(max_read)):
            return Format
    return None


def get_registry():
    return _registry


def register(name, format_class):
    get_registry()[name] = format_class
  1. Apply the Rename Method refactoring with the new name '_registry' to the method 'get_registry'

Closing. Ticket merged into #779.