Skip to content

Commit fa56370

Browse files
committedAug 21, 2023
Deprecate utils.is_str
We don't support Python 2 since a long time now
1 parent ce011e1 commit fa56370

File tree

8 files changed

+17
-15
lines changed

8 files changed

+17
-15
lines changed
 

‎src/pygccxml/declarations/container_traits.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ def remove_defaults(self, type_or_string):
522522
"""
523523

524524
name = type_or_string
525-
if not utils.is_str(type_or_string):
525+
if not isinstance(type_or_string, str):
526526
name = self.class_declaration(type_or_string).name
527527
if not self.remove_defaults_impl:
528528
return name
@@ -705,7 +705,7 @@ def find_container_traits(cls_or_string):
705705
declarations.container_traits: a container traits
706706
"""
707707

708-
if utils.is_str(cls_or_string):
708+
if isinstance(cls_or_string, str):
709709
if not templates.is_instantiation(cls_or_string):
710710
return None
711711
name = templates.name(cls_or_string)

‎src/pygccxml/declarations/type_traits.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ def is_std_string(type_):
507507
508508
"""
509509

510-
if utils.is_str(type_):
510+
if isinstance(type_, str):
511511
return type_ in string_equivalences
512512

513513
type_ = remove_alias(type_)
@@ -522,7 +522,7 @@ def is_std_wstring(type_):
522522
523523
"""
524524

525-
if utils.is_str(type_):
525+
if isinstance(type_, str):
526526
return type_ in wstring_equivalences
527527

528528
type_ = remove_alias(type_)
@@ -537,7 +537,7 @@ def is_std_ostream(type_):
537537
538538
"""
539539

540-
if utils.is_str(type_):
540+
if isinstance(type_, str):
541541
return type_ in ostream_equivalences
542542

543543
type_ = remove_alias(type_)
@@ -552,7 +552,7 @@ def is_std_wostream(type_):
552552
553553
"""
554554

555-
if utils.is_str(type_):
555+
if isinstance(type_, str):
556556
return type_ in wostream_equivalences
557557

558558
type_ = remove_alias(type_)

‎src/pygccxml/parser/config.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
from ConfigParser import SafeConfigParser as ConfigParser
2323
except ImportError:
2424
from configparser import ConfigParser
25-
from .. import utils
2625

2726

2827
class parser_configuration_t(object):
@@ -383,7 +382,7 @@ def load_xml_generator_configuration(configuration, **defaults):
383382
384383
"""
385384
parser = configuration
386-
if utils.is_str(configuration):
385+
if isinstance(configuration, str):
387386
parser = ConfigParser()
388387
parser.read(configuration)
389388

‎src/pygccxml/parser/linker.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
# See http://www.boost.org/LICENSE_1_0.txt
55

66
from pygccxml import declarations
7-
from .. import utils
87

98

109
class linker_t(
@@ -304,7 +303,7 @@ def visit_member_variable_type(self):
304303
self.__link_compound_type()
305304

306305
def visit_declarated(self):
307-
if utils.is_str(self.__inst.declaration):
306+
if isinstance(self.__inst.declaration, str):
308307
self.__inst.declaration = self.__decls[self.__inst.declaration]
309308

310309
def visit_restrict(self):

‎src/pygccxml/parser/project_reader.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ def __init__(self, config, cache=None, decl_factory=None):
187187
self.__dcache = None
188188
if isinstance(cache, declarations_cache.cache_base_t):
189189
self.__dcache = cache
190-
elif utils.is_str(cache):
190+
elif isinstance(cache, str):
191191
self.__dcache = declarations_cache.file_cache_t(cache)
192192
else:
193193
self.__dcache = declarations_cache.dummy_cache_t()
@@ -221,7 +221,7 @@ def get_os_file_names(files):
221221

222222
fnames = []
223223
for f in files:
224-
if utils.is_str(f):
224+
if isinstance(f, str):
225225
fnames.append(f)
226226
elif isinstance(f, file_configuration_t):
227227
if f.content_type in (

‎src/pygccxml/parser/scanner.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ def startElement(self, name, attrs):
334334
self.__update_membership(attrs)
335335
self.__read_attributes(obj, attrs)
336336

337-
elif utils.is_str(obj):
337+
elif isinstance(obj, str):
338338

339339
self.__files[element_id] = os.path.normpath(obj)
340340

‎src/pygccxml/utils/utils.py

+5
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ def is_str(string):
2626
bool: True or False
2727
2828
"""
29+
warnings.warn(
30+
"The is_str function is deprecated. \
31+
Use isinstance(string, str) instead.",
32+
DeprecationWarning)
33+
2934
if sys.version_info[:2] >= (3, 0):
3035
return isinstance(string, str)
3136

‎unittests/find_container_traits_tester.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
from pygccxml import parser
1111
from pygccxml import declarations
12-
from pygccxml import utils
1312

1413

1514
class Test(parser_test_case.parser_test_case_t):
@@ -30,7 +29,7 @@ def setUp(self):
3029
self.global_ns = Test.global_ns
3130

3231
def __cmp_traits(self, typedef, expected, partial_name, key_type=None):
33-
if utils.is_str(typedef):
32+
if isinstance(typedef, str):
3433
typedef = self.global_ns.typedef(typedef)
3534
traits = declarations.find_container_traits(typedef)
3635
self.assertTrue(

0 commit comments

Comments
 (0)