Skip to content

Update deprecated and discouraged code constructs#33

Merged
Zitrax merged 1 commit intoZitrax:masterfrom
Sichter:Patches
May 3, 2025
Merged

Update deprecated and discouraged code constructs#33
Zitrax merged 1 commit intoZitrax:masterfrom
Sichter:Patches

Conversation

@Sichter
Copy link
Copy Markdown
Collaborator

@Sichter Sichter commented May 3, 2025

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 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, e.g. 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 it will catch even terminating exceptions – that 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(): This function is deprecated, let’s use active_count() instead.

All of these changes should be backward compatible and work also in older versions of Python 3.x.

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.
@Zitrax
Copy link
Copy Markdown
Owner

Zitrax commented May 3, 2025

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.

@Zitrax Zitrax merged commit 34db64d into Zitrax:master May 3, 2025
@Sichter
Copy link
Copy Markdown
Collaborator Author

Sichter commented May 3, 2025

Thank you very much, Zitrax! I promise some more interesting (and, hopefully, useful) pull requests will come soon … All the best!

@katiechan
Copy link
Copy Markdown
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.

@Sichter
Copy link
Copy Markdown
Collaborator Author

Sichter commented May 4, 2025

Two runs of the bot later it seems to operate normally so I hope the code changes were OK.

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.

3 participants