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

Autofix breaks code: lambda-assignment in class body #6620

Closed
Adamantish opened this issue Aug 16, 2023 · 3 comments
Closed

Autofix breaks code: lambda-assignment in class body #6620

Adamantish opened this issue Aug 16, 2023 · 3 comments
Labels
accepted Ready for implementation bug Something isn't working

Comments

@Adamantish
Copy link

Version: 0.0.284
Config: No config. Just evaluating ruff.
Command: ruff src --isolated --fix

Codebase uses lambdas as values in an Enum. Whether that be considered a nice trick or not, it certainly doesn't work if those assignments are turned into methods.

class TemperatureScales(Enum):
    CELSIUS = (lambda deg_c: deg_c)
    FAHRENHEIT = (lambda deg_c: deg_c * 9 / 5 + 32)

# will not work if converted to:

class TemperatureScales(Enum):
    def CELSIUS(deg_c):
        return deg_c
    def FAHRENHEIT(deg_c):
        return deg_c * 9 / 5 + 32
@Adamantish Adamantish changed the title Autofix breaks code: lambda-assignment Autofix breaks code: lambda-assignment in class body Aug 16, 2023
@charliermarsh charliermarsh added bug Something isn't working accepted Ready for implementation labels Aug 16, 2023
@charliermarsh
Copy link
Member

Thanks! It turns out that we already mark this as a manual-only fix when it's within a class. So it will automatically be avoided once we start respecting those annotations in the CLI.

@charliermarsh
Copy link
Member

Ah, we only do so for lambdas with annotations. I can change that.

charliermarsh added a commit that referenced this issue Aug 17, 2023
## Summary

Related to #6620 (although that
will only be truly closed once we respect manual fixes on the CLI).
@charliermarsh
Copy link
Member

Closing this optimistically as we've now marked these as "manual only" fixes. Once we respect those annotations in the CLI, we'll avoid these breakages in the future (though the violations themselves will still be raised, so either way I'd suggest a # noqa here). Thanks again for reporting!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted Ready for implementation bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants