Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Tracked by #779
jonhnanthan opened this issue Feb 27, 2024 · 1 comment

Comments

@jonhnanthan
Copy link

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'
@jonhnanthan jonhnanthan added the bug Unexpected or incorrect user-visible behavior label Feb 27, 2024
@lieryan
Copy link
Member

lieryan commented Mar 12, 2024

Closing. Ticket merged into #779.

@lieryan lieryan closed this as not planned Won't fix, can't repro, duplicate, stale Mar 12, 2024
@lieryan lieryan added enhancement and removed bug Unexpected or incorrect user-visible behavior labels Mar 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants