sourcery-ai / sourcery

Instant AI code reviews
https://sourcery.ai
MIT License
1.53k stars 66 forks source link

Sourcery does not recognizes docstrings #256

Closed psstpakGithub closed 2 years ago

psstpakGithub commented 2 years ago

Sourcery fails to recognize python docstrings, and the refactoring it offers delete the entire class/function

the "problem" it reports is Sourcery - Remove unnecessary call to str() within print() (removes comment)

Sourcery Version v0.12.3

Code editor or IDE name and version

Python 3.9 in VS Code

OS name and version

Windows 10 21H2

bm424 commented 2 years ago

Hi @psstpakGithub, thanks for reporting. I can't easily reproduce the issue - Sourcery is correctly preserving docstrings in the example below. If possible, can you share an example of the code Sourcery is breaking on?

class HatPicker(Picker):
    """Interface for picking hats."""

    def pick_hat(self, available_hats: Dict[Label, Hat]):
        """Gets your favourite hat from the list of available hats."""

        if self.favourite_hat in available_hats:
            hat_to_wear = available_hats[self.favourite_hat]
        else:
            hat_to_wear = NO_HAT
        return hat_to_wear
# becomes
class HatPicker(Picker):
    """Interface for picking hats."""

    def pick_hat(self, available_hats: Dict[Label, Hat]):
        """Gets your favourite hat from the list of available hats."""

        return available_hats.get(self.favourite_hat, NO_HAT)
Hellebore commented 2 years ago

Hi @psstpakGithub - will close this as we can't reproduce it. Please do re-open it with a code example and we'll work to resolve it.