-
Notifications
You must be signed in to change notification settings - Fork 10.9k
Use getfullargspec under the scenes for py3 to stop DeprecationWarning #2864
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
Use getfullargspec under the scenes for py3 to stop DeprecationWarning #2864
Conversation
Codecov Report
@@ Coverage Diff @@
## master #2864 +/- ##
=========================================
+ Coverage 84.69% 84.7% +<.01%
=========================================
Files 164 164
Lines 9189 9192 +3
Branches 1369 1370 +1
=========================================
+ Hits 7783 7786 +3
Misses 1154 1154
Partials 252 252
|
scrapy/utils/python.py
Outdated
def getargspec(func): | ||
full_argspec = list(inspect.getfullargspec(func)) | ||
return inspect.ArgSpec(*full_argspec[:4]) | ||
inspect.getargspec = getargspec |
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.
What do you think about creating an utility function and using it, without patching inspect module?
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.
any name suggestion? getargspec_py23
?
scrapy/utils/python.py
Outdated
>>> getargspec_py23(f) | ||
ArgSpec(args=['a', 'b'], varargs='ar', keywords='kw', defaults=(2,)) | ||
""" | ||
if six.PY3: |
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.
If I recall, @kmike prefers if not six.PY2
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.
I would go the other way around:
if six.PY2:
return inspect.getargspec(func)
return inspect.ArgSpec(*inspect.getfullargspec(func)[:4])
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.
And I would make this function private, so we reserve the right to drop it if not needed by other utils in this module.
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.
ok, makes sense to do that as long as usage of inspect.getargspec
stays within the utils.python
module, as is now. If at some point inspect.getargspec
gets used outside, it probably makes sense to do from scrapy.utils.python import getargspec
instead of from inspect import getargspec
to be able to use that for both py2 and py3 without triggering deprecation warning.
thanks! |
fixes #2862
I also ran
tox
for the tests, but there are slight differences for the packages used inside the library, so intests/requirements.txt
:netlib
can be easily updated to0.17
to support both py2 and py3mitmproxy
on the other hand can't w/o some modifications; its version0.18+
that supports both py3 and py2 doesn't containlibmproxy
that's used intests/test_proxy_connect.py
. So yea, related to enable test_proxy_connect in Python 3 #2545 actually, so nevermind.Other than that issue, everything worked fine, no errors for py2 nor py3.
Also I tested the branch in our project and the
DeprecationWarning
has disappeared now :).