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

pywintypes.py: DeprecationWarning: getargs: The 'u' format is deprecated. Use 'U' instead. #1802

Closed
jiasli opened this issue Nov 17, 2021 · 3 comments · Fixed by #1815
Closed

Comments

@jiasli
Copy link

jiasli commented Nov 17, 2021

  • Expected behavior and actual behavior.

No DeprecationWarning should be shown.

  • Steps to reproduce the problem.
> cat test_pywin32.py
def test_pywin32():
    import pywintypes

> pytest .\test_pywin32.py
===================================================== test session starts =====================================================
platform win32 -- Python 3.10.0, pytest-6.2.5, py-1.11.0, pluggy-1.0.0
rootdir: D:\cli\testproj
plugins: forked-1.3.0, xdist-2.4.0
collected 1 item

test_pywin32.py .                                                                                                        [100%]

====================================================== warnings summary =======================================================
test_pywin32.py::test_pywin32
  D:\cli\py310\lib\site-packages\win32\lib\pywintypes.py:54: DeprecationWarning: getargs: The 'u' format is deprecated. Use 'U' instead.
    found = _win32sysloader.GetModuleFilename(filename)

test_pywin32.py::test_pywin32
  D:\cli\py310\lib\site-packages\win32\lib\pywintypes.py:68: DeprecationWarning: getargs: The 'u' format is deprecated. Use 'U' instead.
    found = _win32sysloader.LoadModule(filename)

-- Docs: https://docs.pytest.org/en/stable/warnings.html
================================================ 1 passed, 2 warnings in 0.13s ================================================
  • Version of Python and pywin32
> python -V
Python 3.10.0

> pip list | Select-String pywin32

pywin32                                 302
@juliangilbey
Copy link

I'm seeing the same issue, but I don't have pywin32 installed and I'm not running on a Windows machine. There's some other underlying cause of this DeprecationWarning, but I don't know where it is.

@Tolker-KU
Copy link
Contributor

I've done a bit of digging. This warnings seems to come from passing "u" as a format string to PyArg_ParseTuple here:

static PyObject *PyGetModuleFilename(PyObject *self, PyObject *args)
{
// For py3k, will be built with UNICODE defined
#ifdef UNICODE
static char *fmt = "u";
#else
static char *fmt = "s";
#endif
TCHAR *modName = NULL;
if (!PyArg_ParseTuple(args, fmt, &modName))
return NULL;

and/or here:
static PyObject *PyLoadModule(PyObject *self, PyObject *args)
{
#ifdef UNICODE
static char *fmt = "u";
#else
static char *fmt = "s";
#endif
TCHAR *modName = NULL;
if (!PyArg_ParseTuple(args, fmt, &modName))
return NULL;

Which is deprecated.

Actually solving it and making a PR is the next step

@liudonghua123
Copy link

liudonghua123 commented Mar 8, 2022

I have the same warning, I use python 3.10. And the version of pywin32 installed is 303 which is the latest currently. I hope the new release which fixed this warning could release soon.

From the doc https://docs.python.org/3/c-api/arg.html#strings-and-buffers, I find the following text.

u (str) [const Py_UNICODE *]
Convert a Python Unicode object to a C pointer to a NUL-terminated buffer of Unicode characters. You must pass the address of a Py_UNICODE pointer variable, which will be filled with the pointer to an existing Unicode buffer. Please note that the width of a Py_UNICODE character depends on compilation options (it is either 16 or 32 bits). The Python string must not contain embedded null code points; if it does, a ValueError exception is raised.

Changed in version 3.5: Previously, TypeError was raised when embedded null code points were encountered in the Python string.

Deprecated since version 3.3, will be removed in version 3.12: Part of the old-style Py_UNICODE API; please migrate to using PyUnicode_AsWideCharString().

The 'u' format is already deprecated since 3.3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants