This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: UserString can not be used as string in calls to C routines
Type: enhancement Stage:
Components: Library (Lib) Versions:
Status: closed Resolution: later
Dependencies: Superseder:
Assigned To: gvanrossum Nosy List: Sam.W, gvanrossum, hooft
Priority: normal Keywords:

Created on 2001-02-15 10:25 by hooft, last changed 2022-04-10 16:03 by admin. This issue is now closed.

Messages (4)
msg3371 - (view) Author: Rob W.W. Hooft (hooft) Date: 2001-02-15 10:25
import os,UserString


print os.path.exists(a)
Traceback (most recent call last):
  File "", line 5, in ?
    print os.path.exists(a)
  File "/usr/local/nonius/lib/python2.0/", line 166, in exists
    st = os.stat(path)
TypeError: stat, argument 1: expected string, instance found
msg3372 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2001-02-15 13:40
Alas, this is true.  The same holds for UserDict and UserList.

There is no easy fix.

Fixing this will be a major project, probably for Python 3000.

I'm adding a reminder to PEP 42, and closing the bug report.
msg3373 - (view) Author: Rob W.W. Hooft (hooft) Date: 2001-02-15 15:28
When I submitted the bug, I thought it was very difficult. But
I think there is a bit hackish way to solve it for the UserString.

PyArg_ParseTuple could check for UserString objects if 
a "s" variable is asked for, and return the .data attribute.

Sorry for even proposing it. I'll wait for 3000....
msg162840 - (view) Author: Sam Whitehead (Sam.W) Date: 2012-06-15 03:02
This still seems to be the case in 3.2.

Python 3.2.3 (default, Apr 23 2012, 23:35:30) 
[GCC 4.7.0 20120414 (prerelease)] on linux2

>>> from collections import UserString
>>> a = UserString("foooooop")
>>> import os.path
>>> os.path.exists(a)
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "/usr/lib/python3.2/", line 18, in exists
TypeError: Can't convert 'UserString' object to str implicitly
Date User Action Args
2022-04-10 16:03:45adminsetgithub: 33931
2014-08-13 06:47:14serhiy.storchakalinkissue16773 superseder
2012-06-15 03:02:52Sam.Wsetnosy: + Sam.W
messages: + msg162840
2001-02-15 10:25:29hooftcreate