Minor Python 3 updates

- Remove "u" prefix from strings;
- Raising strings as exception is not valid anymore;
- Convert generators to list where necessary;
- traceback.print_exc accept a limit as first argument, not
  a file (this even for Python 2).

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
This commit is contained in:
Frediano Ziglio 2025-03-24 21:11:15 +00:00 committed by Frediano Ziglio
parent 492c22f444
commit c1b8dbbb9b
3 changed files with 7 additions and 7 deletions

View File

@ -128,13 +128,13 @@ class CodeWriter:
return
if self.at_line_start:
self.out.write(u" " * self.indentation)
self.out.write(" " * self.indentation)
self.at_line_start = False
self.out.write(s)
return self
def newline(self):
self.out.write(u"\n")
self.out.write("\n")
self.at_line_start = True
return self

View File

@ -111,7 +111,7 @@ def fix_attributes(attribute_list, valid_attributes=valid_attributes_generic):
attrs[name] = lst
# only one output attribute can be set
if len(output_attributes.intersection(attrs.keys())) > 1:
if len(output_attributes.intersection(list(attrs.keys()))) > 1:
raise Exception("Multiple output type attributes specified %s" % output_attrs)
return attrs
@ -508,7 +508,7 @@ class ArrayType(Type):
# a constant length array in the C structure is used) or a pointer
# (in this case the pointer allocate the array).
if (not self.is_constant_length()
and len(output_attributes.intersection(member.attributes.keys())) == 0
and len(output_attributes.intersection(list(member.attributes.keys()))) == 0
and not member.member_type.is_pointer()):
raise Exception("Array length must be a constant or some output specifiers must be set")
# These attribute corresponds to specific structure size
@ -1005,7 +1005,7 @@ class MessageType(ContainerType):
if self.name == None:
cms = list(self.reverse_members.keys())
if len(cms) != 1:
raise "Unknown typename for message"
raise Exception("Unknown typename for message")
cm = cms[0]
channelname = cm.channel.member_name
if channelname == None:
@ -1025,7 +1025,7 @@ class MessageType(ContainerType):
if self.name == None:
cms = list(self.reverse_members.keys())
if len(cms) != 1:
raise "Unknown typename for message"
raise Exception("Unknown typename for message")
cm = cms[0]
channelname = cm.channel.member_name
if channelname == None:

View File

@ -277,7 +277,7 @@ current:
except:
print('type %s' % t, file=sys.stderr)
print(writer.getvalue(), file=sys.stderr)
traceback.print_exc(sys.stderr)
traceback.print_exc(file=sys.stderr)
sys.exit(1)
def generate_declarations():