Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warn with stacklevel=2 to show caller of deprecation #3136

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

hugovk
Copy link
Contributor

@hugovk hugovk commented Mar 5, 2024

Summary

With httpx==0.27.0, I'm getting deprecation warnings like:

  /Users/hugo/my-project/.tox/py312/.venv/lib/python3.12/site-packages/httpx/_client.py:680: DeprecationWarning: The 'app' shortcut is now deprecated. Use the explicit style 'transport=WSGITransport(app=...)' instead.
    warnings.warn(message, DeprecationWarning)

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html

This points to where the deprecated code is in HTTPX and isn't actionable for me.

Instead, if would be more helpful to point to where the deprecated code is being called from, so I can fix my code (or report to the library).

Adding stacklevel=2 gives:

  /Users/hugo/my-project/.tox/py312/.venv/lib/python3.12/site-packages/litestar/testing/client/sync_client.py:77: DeprecationWarning: The 'app' shortcut is now deprecated. Use the explicit style 'transport=WSGITransport(app=...)' instead.
    Client.__init__(

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html

(Aha, so Litestar needs fixing! And they've already fixed and released: litestar-org/litestar#3140, I just need to update 馃憤)


Digging a big deeper, I see there used to be a helper function in httpx/_utils.py:

def warn_deprecated(message: str) -> None:  # pragma: nocover	
    warnings.warn(message, DeprecationWarning, stacklevel=2)	

It was introduced in #963, and removed in #1597.

Should we add it back?

Checklist

  • I understand that this PR may be closed in case there was no previous discussion. (This doesn't apply to typos!)
  • [n/a?] I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • [n/a?] I've updated the documentation accordingly.

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.

None yet

1 participant