MAINT: Adding ruff unsafe-fixes - #236
Conversation
Signed-off-by: Pradyot Ranjan <99216956+pradyotRanjan@users.noreply.github.com>
Signed-off-by: Pradyot Ranjan <99216956+pradyotRanjan@users.noreply.github.com>
| try: | ||
| from typing import Self | ||
| except ImportError: # Python < 3.11 | ||
| from typing_extensions import Self |
There was a problem hiding this comment.
Any better way to do this?
There was a problem hiding this comment.
TBH this whole -> Array -to- -> Self thingy is a very typical example of two kinds of nonsense: one from typing and another from linting.
This is all make-work. It's make-work to create a patch, it's make-work to review, it's make-work to even think about any of this. Why oh why does anyone spends any part of their waking time actually thinking about whether an __iadd__ returns an Array or Self? Why does this whole contraption asks us to read about PEP673 --- okay, I googled it, I skimmed through it, fine; however long it took me, it's wasted time --- I'm ready to believe that somebody somewhere somehow cares about this and there exists at least one situation where it matters for whatever definition of matter, okay. But why on good green earth, why does it get inflicted on us?
Anyhow, I'm done venting.
Short answer: from my perch, I don't care, as long as this does not get in the way (as in, I'll probably have to pip install something next time I do actual work in an environment with python==3.10, OK, I'll do it once and move on doing actual work).
ev-br
left a comment
There was a problem hiding this comment.
I'd like to understand why these are unsfafe-fixes. The changes seem to be of two groups:
- typing
-> Arrayreplaced by-> Self(ok whatever)
This should be perfectly safe at runtime - nested ifs collapsed with either
andorisinstance(object, tuple_of_types)
The former form shortcuts fine, the latter... probably shortcuts too, not sure.
Plus benign refactors ofif-elseinto adict.getetc.
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?
| try: | ||
| from typing import Self | ||
| except ImportError: # Python < 3.11 | ||
| from typing_extensions import Self |
There was a problem hiding this comment.
TBH this whole -> Array -to- -> Self thingy is a very typical example of two kinds of nonsense: one from typing and another from linting.
This is all make-work. It's make-work to create a patch, it's make-work to review, it's make-work to even think about any of this. Why oh why does anyone spends any part of their waking time actually thinking about whether an __iadd__ returns an Array or Self? Why does this whole contraption asks us to read about PEP673 --- okay, I googled it, I skimmed through it, fine; however long it took me, it's wasted time --- I'm ready to believe that somebody somewhere somehow cares about this and there exists at least one situation where it matters for whatever definition of matter, okay. But why on good green earth, why does it get inflicted on us?
Anyhow, I'm done venting.
Short answer: from my perch, I don't care, as long as this does not get in the way (as in, I'll probably have to pip install something next time I do actual work in an environment with python==3.10, OK, I'll do it once and move on doing actual work).
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 For the second part, I'm not sure about it either. |
|
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. |
Towards #228