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

Sourcery mistakes function after a class in a script as member of the class - bug report #234

Closed
Estrangeling opened this issue Oct 14, 2023 · 1 comment
Assignees

Comments

@Estrangeling
Copy link

Estrangeling commented Oct 14, 2023

I am using Visual Studio Code with Sourcery extension.

And I have encountered the bug multiple times, the bug is as follows:

Inside a script, if there is a class defined above a function, the function isn't a member of the class, Sourcery will mistake the function as a member of the class and show the following message:

Sourcery - The first argument to instance methods should be `self` sourcery(refactoring:instance-method-first-arg-name)

This is a bug, the function isn't part of the class definition. This can happen for various reasons, but the bug most frequently occurs when a class is added before a function in a script.

As an example:

class Button_Animation(QObject):
    stopped = pyqtSignal()
    change = pyqtSignal()
    update = pyqtSignal()

    def run(self):
        while GLOBALS["run"]:
            self.animate()

        self.reset()

    def animate(self):
        while GLOBALS["pause"]:
            QTest.qWait(42)

        choices = list(range(12))
        for name in TRINITY:
            choice = random.choice(choices)
            choices.remove(choice)
            BUTTONS[choice] = name

        texts = random.choices(TRINITY, k=9)
        for name, i in zip(texts, choices):
            BUTTONS[i] = name

        self.change.emit()
        self.update.emit()

    def reset(self):
        global BUTTONS
        BUTTONS = BUTTONS_COPY.copy()
        self.change.emit()
        self.update.emit()


def init_connection(obj, worker, key):
    thread = QThread()
    worker.moveToThread(thread)
    thread.started.connect(worker.run)
    worker.stopped.connect(thread.quit)
    GLOBALS[key] = worker
    obj.qthread = thread

2023-10-15_014057

The message goes away if I close the editor and reopen it. But it will easily resurface if I add a new class or edit a class defined before a function.

How can I fix this?

@bm424 bm424 self-assigned this Oct 16, 2023
@bm424
Copy link
Contributor

bm424 commented Oct 16, 2023

Hi @Estrangeling, this looks very much like a bug with our pattern matching system. I'll investigate and we'll hopefully have a fix in the next release.

This is the same as sourcery-ai/sourcery#328, so I'm going to close this issue in favour of the older one.

@bm424 bm424 closed this as completed Oct 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants