Skip to content

Commit

Permalink
Add type annotations to Spacer
Browse files Browse the repository at this point in the history
Task-number: QTBUG-129564
Pick-to: 6.8
Change-Id: I942d135da630f7ba6641170a1a597b0578aca878
Reviewed-by: Cristian Maureira-Fredes <[email protected]>
  • Loading branch information
Mate Barany committed Nov 8, 2024
1 parent 05b5de9 commit 519d3d3
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions util/locale_database/qlocalexml.py
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ def __eachEltInGroup(cls, parent: minidom.Element, group: str, key: str


class Spacer (object):
def __init__(self, indent = None, initial = ''):
def __init__(self, indent:str|int|None = None, initial: str = '') -> None:
"""Prepare to manage indentation and line breaks.
Arguments are both optional.
Expand All @@ -590,17 +590,17 @@ def __init__(self, indent = None, initial = ''):
an end-tag. The text is not parsed any more carefully than
just described."""
if indent is None:
self.__call = lambda x: x
self.__call: Callable[[str], str] = lambda x: x
else:
self.__each = ' ' * indent if isinstance(indent, int) else indent
self.__each: str = ' ' * indent if isinstance(indent, int) else indent
self.current = initial
self.__call = self.__wrap

def __wrap(self, line):
def __wrap(self, line: str) -> str:
if not line:
return '\n'

indent = self.current
indent: str = self.current
if line.startswith('</'):
indent = self.current = indent[:-len(self.__each)]
elif line.startswith('<') and line[1:2] not in '!?':
Expand All @@ -611,7 +611,7 @@ def __wrap(self, line):
self.current += self.__each
return indent + line + '\n'

def __call__(self, line):
def __call__(self, line: str) -> str:
return self.__call(line)

class QLocaleXmlWriter (object):
Expand Down

0 comments on commit 519d3d3

Please sign in to comment.