Xqt created this task. Xqt added projects: Pywikibot, good first task. Restricted Application added subscribers: pywikibot-bugs-list, Aklapper. Restricted Application added a comment.
Thank you for tagging this task with #good_first_task <https://phabricator.wikimedia.org/tag/good_first_task/> for Wikimedia newcomers! Newcomers often may not be aware of things that may seem obvious to seasoned contributors, so please take a moment to reflect on how this task might look to somebody who has never contributed to Wikimedia projects. A #good_first_task <https://phabricator.wikimedia.org/tag/good_first_task/> is a self-contained, non-controversial task with a clear approach. It should be well-described with pointers to help a completely new contributor, for example it should clearly point to the codebase URL and provide clear steps to help a contributor get set up for success. We've included some guidelines at https://phabricator.wikimedia.org/tag/good_first_task/ ! Thank you for helping us drive new contributions to our projects <3 TASK DESCRIPTION **Introduction** Python 3.11 introduced the `Exception.add_note()` method, which allows attaching additional context notes to exceptions. These notes are displayed in the exception traceback, helping developers debug issues more easily. Pywikibot currently needs to support older Python versions (< 3.11). To provide similar functionality, we want to backport `add_note()` method for all `exceptions.Error` classes. **Goal** Refactor `pywikibot.exceptions.Error` of the exceptions module <https://doc.wikimedia.org/pywikibot/master/api_ref/exceptions.html#module-exception> to derive from a new `BaseError` instead of the built-in `Exception`. For Python < 3.11, `BaseError` should implement Python 3.11-style `Exception.add_note()` functionality within backports module <https://doc.wikimedia.org/pywikibot/master/api_ref/x_backports.html#module-backports>. **Steps** 1. Create a new class `BaseError` in the backports module <https://doc.wikimedia.org/pywikibot/master/api_ref/x_backports.html#module-backports> - Derive `BaseError` from `Exception`. - For Python < 3.11 (`tools.PYTHON_VERSION < (3, 11)`): - Implement `add_note(self, note: str)` storing notes in an instance attribute `self.__notes__`. - Override `__str__()` so that `super().__str__()` is followed by each note on a new line. 2. Import `BaseError` from `backports` as `_BaseError` in the in exceptions module <https://doc.wikimedia.org/pywikibot/master/api_ref/exceptions.html#module-exception> (_BaseError to keep the class private). Make `pywikibot.exceptions.Error` inherit from `_BaseError` instead of `Exception`. 3. Example usage: >>> try: >>> 1/0 >>> except pywikibot.exceptions.Error as e: >>> e.add_note('omg!') >>> e.add_note('does it work?') >>> raise Traceback (most recent call last): ... ZeroDivisionError: division by zero omg! does it work? **Further help** - https://doc.wikimedia.org/pywikibot/master/index.html - T407059 <https://phabricator.wikimedia.org/T407059> - https://www.mediawiki.org/wiki/Special:MyLanguage/Manual:Pywikibot/Development - https://www.mediawiki.org/wiki/Manual:Coding_conventions/Python - https://www.mediawiki.org/wiki/Manual:Pywikibot/Development/Guidelines **Hint** pre-commit is strictly recommended before submitting a patch. Install it with `pip install pre-commit` and run it with `pre-commit run --all-files` TASK DETAIL https://phabricator.wikimedia.org/T416566 EMAIL PREFERENCES https://phabricator.wikimedia.org/settings/panel/emailpreferences/
_______________________________________________ pywikibot-bugs mailing list -- [email protected] To unsubscribe send an email to [email protected]
