Skip to content

MAINT: Adding ruff unsafe-fixes - #236

Merged
ev-br merged 3 commits into
data-apis:mainfrom
prady0t:ruff-unsafe-fixes
Jul 31, 2026
Merged

MAINT: Adding ruff unsafe-fixes#236
ev-br merged 3 commits into
data-apis:mainfrom
prady0t:ruff-unsafe-fixes

Conversation

@prady0t

@prady0t prady0t commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Towards #228

prady0t added 2 commits July 30, 2026 22:45
Signed-off-by: Pradyot Ranjan <99216956+pradyotRanjan@users.noreply.github.com>
Signed-off-by: Pradyot Ranjan <99216956+pradyotRanjan@users.noreply.github.com>
Comment thread array_api_strict/_array_object.py

@ev-br ev-br left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to understand why these are unsfafe-fixes. The changes seem to be of two groups:

  • typing -> Array replaced by -> Self (ok whatever)
    This should be perfectly safe at runtime
  • nested ifs collapsed with either and or isinstance(object, tuple_of_types)
    The former form shortcuts fine, the latter... probably shortcuts too, not sure.
    Plus benign refactors of if-else into a dict.get etc.

And if it's labeled as unsafe, it means I don't see something, so what is it I'm not seeing: Which of these is unsafe and how?

Comment thread array_api_strict/_array_object.py
@prady0t

prady0t commented Jul 30, 2026

Copy link
Copy Markdown
Contributor Author

I'd like to understand why these are unsfafe-fixes.

See: https://docs.astral.sh/ruff/linter/#fix-safety

I think for the first part: the conditional import is something that I added manually; originally Ruff just imported Self from typing. But for older versions, it's only available in typing_extensions. And the CI did fail on that.

For the second part, I'm not sure about it either.

@ev-br

ev-br commented Jul 30, 2026

Copy link
Copy Markdown
Member

Thanks for the link. My question is still why these fixes are "unsafe" in the meaning of that link: what are the changes to the runtime behaviour.

@prady0t

prady0t commented Jul 30, 2026

Copy link
Copy Markdown
Contributor Author

After a bit more digging through the docs:

This rule's fix is marked as unsafe as it changes the meaning of your type annotations.

When preview is enabled, the fix for this rule is considered as safe. When preview is not enabled, the fix is always considered unsafe.

@ev-br

ev-br commented Jul 31, 2026

Copy link
Copy Markdown
Member

Thanks for digging through their docs! It all makes sense now.
For SIM102 could you please keep the changes but disable the rule globally? And then merge.
Reason: starting from a nested if, it will first collapse it into one, then activate the line length rule and break the line with brackets. The net effect is even funnier indentation, plus back-and-forth for a human author.

@prady0t

prady0t commented Jul 31, 2026

Copy link
Copy Markdown
Contributor Author

The net effect is even funnier indentation, plus back-and-forth for a human author.

Totally agreed!

Signed-off-by: Pradyot Ranjan <99216956+pradyotRanjan@users.noreply.github.com>
@prady0t

prady0t commented Jul 31, 2026

Copy link
Copy Markdown
Contributor Author

Also added some comments in ruff.toml

@ev-br
ev-br merged commit 6558d18 into data-apis:main Jul 31, 2026
15 checks passed
@ev-br

ev-br commented Jul 31, 2026

Copy link
Copy Markdown
Member

Thank you @prady0t , merged.

@ev-br ev-br added this to the 2.7 milestone Jul 31, 2026
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

Successfully merging this pull request may close these issues.

2 participants