Skip to content

Commit 65b39ed

Browse files
committed
Update std::basic_string pythonizations
1 parent f4f859f commit 65b39ed

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

python/cppyy/__init__.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,14 +125,18 @@ def tuple_getitem(self, idx, get=cppyy.gbl.std.get):
125125
raise IndexError(idx)
126126
pyclass.__getitem__ = tuple_getitem
127127

128-
# pythoniztion of std::string; placed here because it's simpler to write the
128+
# pythonization of std::basic_string<char>; placed here because it's simpler to write the
129129
# custom "npos" object (to allow easy result checking of find/rfind) in Python
130130
elif pyclass.__cpp_name__ == "std::basic_string<char>":
131-
class NPOS(0x3000000 <= sys.hexversion and int or long):
131+
class NPOS(int):
132+
def __init__(self, npos):
133+
self.__cpp_npos = npos
132134
def __eq__(self, other):
133-
return other == -1 or int(self) == other
135+
return other == -1 or other == self.__cpp_npos
134136
def __ne__(self, other):
135-
return other != -1 and int(self) != other
137+
return other != -1 and other != self.__cpp_npos
138+
if hasattr(pyclass.__class__, 'npos'):
139+
del pyclass.__class__.npos # drop b/c is const data
136140
pyclass.npos = NPOS(pyclass.npos)
137141

138142
return True

0 commit comments

Comments
 (0)