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

style: Modernize object inheritance, super() calls, and OSError aliases #3251

Merged
merged 5 commits into from
Dec 12, 2023

Conversation

echoix
Copy link
Member

@echoix echoix commented Nov 19, 2023

In prevision of being able to introduce some faster (and more complete) Python checks, like with using the incredibly fast ruff linter https://docs.astral.sh/ruff/, part of the rules implemented come from pyupgrade https://github.com/asottile/pyupgrade. pyupgrade helps to automatically upgrade syntax to newer versions of Python. In order to reduce the diff if we decide to start using this, I'm starting by applying only three really simple changes, that apply to any version of python past python 3.3 (released in 2012, EOL in 2017).

  1. Remove useless object inheritance:
  2. Simplify super() calls if the first argument is the same class, and the second is equivalent (like self)
  3. Use OSError for all other aliases of OSError.

So in essence these are quite unlikely to cause serious regressions, as it is how it is supposed to work for a long time already.
The pyupgrade tool also has some filters to choose what minimum python version you want to support. After trying with --py37-plus, I started again with --py3-only and disabled the most I could. I then passed through the 300+ files to only keep these 3 changes

@echoix
Copy link
Member Author

echoix commented Nov 19, 2023

I might want some feedback on if the changes should be kept in the cgentypes folder, some of it seems like it is copied from another project. I wasn't sure if you were patching these up or it just wasn't in sync (like the lex.py file)

@nilason
Copy link
Contributor

nilason commented Nov 19, 2023

I might want some feedback on if the changes should be kept in the cgentypes folder, some of it seems like it is copied from another project. I wasn't sure if you were patching these up or it just wasn't in sync (like the lex.py file)

I'd recommend leave out any non-critical changes from python/libgrass_interface_generator/ctypesgen directory. As noted in https://github.com/OSGeo/grass/blob/main/python/libgrass_interface_generator/README.md, any patches should be reported upstreams. Changes to ctypesgen, not listed in the README file, will be null and void by next update of the package. (I see now there are actually such changes, unfortunately).

Copy link
Member Author

@echoix echoix left a comment

Choose a reason for hiding this comment

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

To revert

@echoix
Copy link
Member Author

echoix commented Nov 20, 2023

Since indeed, by definition it wasn't that essential, I reverted the changes from that folder

Changes to ctypesgen, not listed in the README file, will be null and void by next update of the package. (I see now there are actually such changes, unfortunately).

Maybe something that later could be handled in the periodic update workflow from #3200, wink wink!

@neteler neteler added this to the 8.4.0 milestone Nov 21, 2023
@echoix echoix mentioned this pull request Dec 3, 2023
2 tasks
@echoix
Copy link
Member Author

echoix commented Dec 12, 2023

Since all checks have passed, is still up to date, and had 2 reviews, I think it could be ready to merge ;)

@neteler neteler added the Python Related code is in Python label Dec 12, 2023
@petrasovaa petrasovaa merged commit a71b72a into OSGeo:main Dec 12, 2023
19 checks passed
@echoix echoix deleted the pyupgrade-patch1 branch December 26, 2023 13:02
HuidaeCho pushed a commit to HuidaeCho/grass that referenced this pull request Jan 9, 2024
@wenzeslaus wenzeslaus changed the title Modernize object inheritance, super() calls, and OSError aliases style: Modernize object inheritance, super() calls, and OSError aliases Jun 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Python Related code is in Python
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants