-
Notifications
You must be signed in to change notification settings - Fork 126
When raising LDAPBytesWarning, walk the stack to determine stacklevel #128
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
@tiran, does this look OK? |
bb97d6f
to
f215bab
Compare
Lib/ldap/ldapobject.py
Outdated
# and in the _ldap extension, based on a marker in globals(). | ||
stacklevel = 0 | ||
try: | ||
getframe = frame = sys._getframe |
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.
Why assign to frame
?
Lib/ldap/ldapobject.py
Outdated
# getting a useful stacklevel is tricky. | ||
# We walk stack frames, ignoring all functions in this file | ||
# and in the _ldap extension, based on a marker in globals(). | ||
stacklevel = 0 |
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.
You can start with an offset of 2, maybe 3.
Codecov Report
@@ Coverage Diff @@
## master #128 +/- ##
==========================================
- Coverage 68.92% 68.92% -0.01%
==========================================
Files 49 49
Lines 4686 4701 +15
Branches 788 790 +2
==========================================
+ Hits 3230 3240 +10
- Misses 1108 1111 +3
- Partials 348 350 +2
Continue to review full report at Codecov.
|
Thanks, will fix. |
f215bab
to
1bdc9f2
Compare
this is slowly leaving "simplification" territory... |
Lib/ldap/ldapobject.py
Outdated
else: | ||
frame = sys._getframe(stacklevel) | ||
# walk up the stacks until we leave the file | ||
while frame and frame.f_globals.get('_LDAP_WARN_SKIP_FRAME'): |
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.
frame is not defined in case sys._getframe
does not exist. Can we rather wrap the whole block into a hasattr(sys, '_getframe')
check?
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.
Oops, thanks for the catch!
Closes: python-ldap#108 Signed-off-by: Christian Heimes <cheimes@redhat.com> Some simplification by: Petr Viktorin
1bdc9f2
to
cf24a54
Compare
I'll be away until Friday, and I'd like to release beta 3 on Friday or Monday. |
The latest version of the PR addresses the stacklevel issue. I'm not quite happy with warnings in general. There are two potential issues:
Both issues can be addressed in new PRs. |
This is a simplification of #120 (and #109).
Turns out extension functions have
globals()
, and putting the marker in the_ldap
module as well means we can only walk the stack – no other changes necessary.BTW I do like removing
_bytesify_inputs
! Let's do that in 3.1.I did have some trouble in py2 tests, see the
_normalize
inner function.