-
Notifications
You must be signed in to change notification settings - Fork 669
chore: create a custom warnings.warn
wrapper
#1882
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’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Codecov Report
@@ Coverage Diff @@
## main #1882 +/- ##
==========================================
+ Coverage 92.50% 92.52% +0.02%
==========================================
Files 78 78
Lines 4871 4885 +14
==========================================
+ Hits 4506 4520 +14
Misses 365 365
Flags with carried forward coverage won't be shown. Click here to find out more.
|
Test script:
With this PR, warning shows against the script:
Without this PR, warning shows against /home/python-gitlab/gitlab/__init__.py:43: DeprecationWarning:
Direct access to 'gitlab.OWNER_ACCESS' is deprecated and will be removed in a future major python-gitlab release. Please use 'gitlab.const.OWNER_ACCESS' instead.
warnings.warn( Also tested the REPL with the PR:
|
4d14986
to
c31c6fe
Compare
Thanks @JohnVillalovos. If I understand correctly you want to show the caller and not the source in our library when showing warnings. Wouldn't this achieve the goal without custom wrappers? warnings.warn(
f"\nDirect access to 'gitlab.{name}' is deprecated and will be "
f"removed in a future major python-gitlab release. Please "
f"use 'gitlab.const.{name}' instead.",
DeprecationWarning,
stacklevel=2,
) Let me know if that works. |
It works but have to determine what Some of these require |
Ahh I see, ok, that wasn't clear to me at first glance. I was hoping it was a simpler one-time thing and we'd avoid having a heated debate about required keyword-only arguments but now we'll have to have it 😅 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just had some comments @JohnVillalovos after the explanation now :)
c31c6fe
to
f72a79a
Compare
7802ade
to
75c5089
Compare
Create a custom `warnings.warn` wrapper that will walk the stack trace to find the first frame outside of the `gitlab/` path to print the warning against. This will make it easier for users to find where in their code the error is generated from
75c5089
to
6ca9aa2
Compare
Create a custom
warnings.warn
wrapper that will walk the stack traceto find the first frame outside of the
gitlab/
path to print thewarning against. This will make it easier for users to find where in
their code the error is generated from