Skip to content

Conversation

jakobheine
Copy link
Contributor

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.

@The-Compiler
Copy link

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 pytest-dev/pytest@477959e for some inspiration.

`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`.

Signed-off-by: jakobheine <[email protected]>
@jakobheine jakobheine force-pushed the td/add-deprecation-warning-urlrequired branch from ce01dd4 to 452cb3f Compare February 2, 2025 07:53
@jakobheine
Copy link
Contributor Author

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

@The-Compiler
Copy link

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).

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