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

Clean up Python 2 styled code #97

Merged
merged 10 commits into from
Apr 26, 2024
Merged

Conversation

Cito
Copy link
Contributor

@Cito Cito commented Apr 25, 2024

Some clean-up since paste only supports Python 3 nowadays:

  • in Python 3, we don't need to inherit from object
  • avoid bare excepts
  • unify the use of "no default" sentinels inside paste
  • source code encodings don't need to be specified

@cdent
Copy link
Collaborator

cdent commented Apr 25, 2024

Are these kind of cleanups worthwhile if we're trying to dissuade the use of paste?

Also if we're trying to keep it as stable as possible, we want to change it as little as possible, don't we?

If, on the other hand, we want to sort of bring it back to life, then these sorts of changes are warranted, but I don't know that we've made that decision.

Are you interested in taking it in that direction?

@Cito
Copy link
Contributor Author

Cito commented Apr 25, 2024

No, I don't want to bring it back to life. Just some cheap clean-up before this is retired for good.

But you may decide. If you think it's not worthwile, just close this.

Btw, I did some fixing/cleanup in PySourceColor, but noticed this code is broken and outdated. It contain bugs and code that cannot run in Python 3 (e.g. calls tokenize with a second parameter that only existed in Python2) , was written for Python 2 as input, and outputs XHTML instead of HTML5.

The only really proper fix in my view would be to completely replace it with Pygments. If you think that is still worthwile, I would submit a PR, otherwise we need to leave it in this broken state. (update: see comment below)

@Cito
Copy link
Contributor Author

Cito commented Apr 25, 2024

Looked a bit deeper and was able to fix the issue with the tokenizer. You can call the PySourceColor module on the command line to verify that it was broken before and now works (with the caveats mentioned above).

This would make the module at least somewhat usable again, and keep things compatible without the need to switch to Pygments.

So I think this whole PR is worthwile to merge. But will end working on paste after this.

@Cito
Copy link
Contributor Author

Cito commented Apr 25, 2024

Btw, another cheap fix of broken Python 2 code is #68 - this is also worthwile to be fixed.

@cdent
Copy link
Collaborator

cdent commented Apr 26, 2024

nice work, thanks

@cdent cdent merged commit f4669c3 into pasteorg:master Apr 26, 2024
6 checks passed
@Cito Cito deleted the modernize-to-python-3 branch April 26, 2024 16:03
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