Update deprecated and discouraged code constructs#33
Merged
Zitrax merged 1 commit intoZitrax:masterfrom May 3, 2025
Merged
Conversation
Sorry to start with these boring and pedantic changes ;–). But I am trying to fix some problems in FPCBot, and during the work on them some deprecated or generally discouraged code constructs become apparent. Therefore I propose to fix the following items. Strings: Unrecognized escape sequences in normal strings produce a DeprecationWarning since Python 3.6 and a SyntaxWarning since Python 3.12. They may produce a SyntaxError in the future. Therefore let's prefix strings containing special RegEx escape sequences like `\(` with `r`. None: Comparisons with None should use `is` or `is not` instead of `==` or `!=` because None is the sole instance of the NoneType type and therefore uses identity checks. Exceptions: Using a bare `except:` is generally discouraged because will catch even terminating exceptions -- which is not what we want. Therefore let's use at least `except Exception:` which catches only non-terminating exceptions. Module `re`, function `split()`: Since Python 3.13 passing the optional parameters `flags` and `maxsplit` as positional arguments is deprecated, they will become keyword-only parameters in the future. Module `re`, function `sub()`: Since Python 3.13 passing the optional parameters `count` and `flags` as positional arguments is deprecated, they will become keyword-only parameters in the future. Module threading, function `activeCount()`: Is deprecated, let’s use `active_count()` instead.
Owner
|
Thanks a lot for looking into this, as I mentioned I am not really active on Wikimedia now. The other collaborator for this repository is @eatcha-wikimedia - I don't know if he/she is active? The changes look good to me, I'll merge them. I assume the bot will pick it up, but I am currently not aware of how it's running now. Ping me if there is any issues. |
Collaborator
Author
|
Thank you very much, Zitrax! I promise some more interesting (and, hopefully, useful) pull requests will come soon … All the best! |
Contributor
|
Thanks Zitrax, the bot should update its code against this repo once a night so we should see the effect of the changes in the next run or two. |
Collaborator
Author
|
Two runs of the bot later it seems to operate normally so I hope the code changes were OK. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Sorry to start with these boring and pedantic changes ;–). But I am trying to fix some problems in FPCBot, and during the work on them some deprecated or generally discouraged code constructs become apparent. Therefore I propose to update the following items.
Strings: Unrecognized escape sequences in normal strings produce a
DeprecationWarningsince Python 3.6 and aSyntaxWarningsince Python 3.12. They may produce aSyntaxErrorin the future. Therefore let’s prefix strings containing special RegEx escape sequences like\(withr, e.g.r"\(".None: Comparisons with
Noneshould useisoris notinstead of==or!=becauseNoneis the sole instance of theNoneTypetype and therefore uses identity checks.Exceptions: Using a bare
except:is generally discouraged because it will catch even terminating exceptions – that is not what we want. Therefore let’s use at leastexcept Exception:which catches only non-terminating exceptions.Module
re, functionsplit(): Since Python 3.13 passing the optional parametersflagsandmaxsplitas positional arguments is deprecated, they will become keyword-only parameters in the future.Module
re, functionsub(): Since Python 3.13 passing the optional parameterscountandflagsas positional arguments is deprecated, they will become keyword-only parameters in the future.Module threading, function
activeCount(): This function is deprecated, let’s useactive_count()instead.All of these changes should be backward compatible and work also in older versions of Python 3.x.