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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Python 3.8 related deprecation warning #600

Open
wants to merge 3 commits into
base: master
from

Conversation

@skeptycal
Copy link

skeptycal commented Nov 28, 2019

#599

added #define PY_SSIZE_T_CLEAN to src/pycurl.h per Python 3.8 documentation

#################################################################
TLDR: indexes should be typed as Py_ssize_t (signed) instead of int to allow the use of full address space (64bit vs. 32bit). The conversion codes 's#' and 't#' will output Py_ssize_t if the macro PY_SSIZE_T_CLEAN is defined before Python.h is included. Use PY_SSIZE_T_CLEAN and make sure all values are correctly converted.

Documentation:
This warning message is new in Python 3.8 and conversion must be complete before 3.10 ...

Use of # variants of formats in parsing or building value (e.g. PyArg_ParseTuple(), Py_BuildValue(), PyObject_CallFunction(), etc.) without PY_SSIZE_T_CLEAN defined raises DeprecationWarning now. It will be removed in 3.10 or 4.0. Read Parsing arguments and building values for detail. (Contributed by Inada Naoki in bpo-36381.)

Raise warning for # use without PY_SSIZE_T_CLEAN.

  • 3.8: PendingDeprecationWarning
  • 3.9: DeprecationWarning
  • 3.10 (or 4.0): Remove PY_SSIZE_T_CLEAN and use Py_ssize_t always

The conversion codes 's#' and 't#' will output Py_ssize_t if the macro PY_SSIZE_T_CLEAN is defined before Python.h is included, and continue to output int if that macro isn't defined.

# installed locally after changes
> pip list
pycurl            7.43.0.3  /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages

> curl --version
curl 7.64.1 (x86_64-apple-darwin19.0) libcurl/7.64.1 (SecureTransport) LibreSSL/2.8.3 zlib/1.2.11 nghttp2/1.39.2

# running test script - no warning found when using pycurl.Curl.perform()
> ./ssm_pycurl.py
pycurl.VERBOSE = 1
pycurl.version = 'PycURL/7.43.0.3 libcurl/7.64.1 SecureTransport (LibreSSL/2.8.3) zlib/1.2.11 nghttp2/1.39.2'
pycurl.version_info() = (4, '7.64.1', 475137, 'x86_64-apple-darwin19.0', 5211037, 'SecureTransport (LibreSSL/2.8.3)', 0, '1.2.11', ('dict', 'file', 'ftp', 'ftps', 'gopher', 'http', 'https', 'imap', 'imaps', 'ldap', 'ldaps', 'pop3', 'pop3s', 'rtsp', 'smb', 'smbs', 'smtp', 'smtps', 'telnet', 'tftp'), None, 0, None)
  • copy of relevant test script portions
#*###################################################################################
class Curl_Wrapper():
    ''' ... [edited for content] ... '''
    def get(self):
        """
        Perform a file transfer and return
        """
        try:
            self.crl.perform()
        except pycurl.error as e:
            self.show_error(e)
            return e
        return self.b_obj.getvalue().decode(self.encoding)
    ''' ... [edited for content] ... '''
#*###################################################################################
test_url: bytes = b'https://wiki.python.org/moin/BeginnersGuide'
crl = Curl_Wrapper(test_url) # per documentation: initializing a Curl object sets VERBOSE = 0
crl.set_verbose() # explicitly set VERBOSE = 1, as requested
response = crl.get()
print(f"{pycurl.VERBOSE = }")
print(f"{pycurl.version = }")
print(f"{pycurl.version_info() = }")
# print(f'Output of GET request:\n{response}') # prints html from url
crl.close()
#*###################################################################################
skeptycal added 2 commits Nov 28, 2019
add #define PY_SSIZE_T_CLEAN (python 3.8 changes: bpo-36381: Raise ``DeprecationWarning`` when '#' formats are used for building or parsing values without ``PY_SSIZE_T_CLEAN`` (https://docs.python.org/3/whatsnew/3.8.html#changes-in-the-c-api)
@p

This comment has been minimized.

Copy link
Member

p commented Dec 2, 2019

Can you please take out gitignore changes and just leave the define in?

@skeptycal

This comment has been minimized.

Copy link
Author

skeptycal commented Dec 5, 2019

Can you please take out gitignore changes and just leave the define in?

Done. Sorry for the config spam.

@eli-schwartz

This comment has been minimized.

Copy link

eli-schwartz commented Dec 5, 2019

@skeptycal I recommend using your global $HOME/.config/git/ignore for this.

Also, you can use git rebase -i origin/master and delete the first and third commit, then force push, instead of creating "commit spam" to revert the "config spam". :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.