requests icon indicating copy to clipboard operation
requests copied to clipboard

refactor(URLRequired): Deprecate URLRequired exception with warning

Open jakobheine opened this issue 1 year ago • 3 comments

requests.URLRequired has been dead code since ab27027 (2012) and is never raised. This commit adds a DeprecationWarning to notify users that it will be removed in a future version. Invalid URLs instead raise MissingSchema, InvalidSchema, or InvalidURL.

jakobheine avatar Feb 01 '25 19:02 jakobheine

Note this only emits a warning when the exception is raised (which would only ever be done in requests code), not when it is caught.

A module-level __getattr__ would instead emit such a warning whenever it is accessed, see e.g. the removed code in https://github.com/pytest-dev/pytest/commit/477959ef7dc9f8491a80ba4d585d737a68f0a34c for some inspiration.

The-Compiler avatar Feb 01 '25 21:02 The-Compiler

Thank you for the review @The-Compiler! I updated the PR accordingly, wdyt now?

jakobheine avatar Feb 02 '25 07:02 jakobheine

This doesn't emit any warnings at all, as shown by a simple test with python -Werror -c "from requests.exceptions import URLRequired".

You'll need to rename URLRequired to something like _URLRequired so that the __getattr__ actually gets called. Most likely after that, an import requests will already emit a warning as that does from .exceptions import URLRequired. See the pytest example above for how to handle that (with another module-level __getattr__ in there).

The-Compiler avatar Feb 03 '25 10:02 The-Compiler