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

UP013, UP014: Comments inside the definition are dropped #9715

Open
JelleZijlstra opened this issue Jan 30, 2024 · 2 comments
Open

UP013, UP014: Comments inside the definition are dropped #9715

JelleZijlstra opened this issue Jan 30, 2024 · 2 comments
Labels
bug Something isn't working fixes Related to suggested fixes for violations help wanted Contributions especially welcome

Comments

@JelleZijlstra
Copy link
Contributor

JelleZijlstra commented Jan 30, 2024

Starting with this code:

from typing import NamedTuple, TypedDict

X = TypedDict("X", {
    "some_config": int,  # important
})

Y = NamedTuple("Y", [
    ("some_config", int),  # important
])

Ruff (via rules UP013 and UP014) turns it into:

from typing import NamedTuple, TypedDict

class X(TypedDict):
    some_config: int

class Y(NamedTuple):
    some_config: int

Ideally it should retain the end-of-line comments.

@AlexWaygood AlexWaygood added fixes Related to suggested fixes for violations bug Something isn't working labels Jan 30, 2024
@chris-griffin
Copy link

Ruff has recently updated their policy to clarify that rule fixes that drop comments should be marked as unsafe.

@AlexWaygood
Copy link
Member

The fix is now marked as unsafe if comments will be dropped, but ideally (as Jelle says) we wouldn't drop them at all in the autofix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fixes Related to suggested fixes for violations help wanted Contributions especially welcome
Projects
None yet
Development

No branches or pull requests

4 participants