Skip to content

Commit

Permalink
fix trailing newlines generated by ComMethodGenerator, `DispPropert…
Browse files Browse the repository at this point in the history
…yGenerator` and `DispMethodGenerator`
  • Loading branch information
junkmd committed Apr 22, 2024
1 parent 2bbbd45 commit 455ac54
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions comtypes/tools/codegenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,15 +235,15 @@ class ComMethodGenerator(object):
def __init__(self, m: typedesc.ComMethod, isdual: bool) -> None:
self._m = m
self._isdual = isdual
self._stream = io.StringIO()
self.data: List[str] = []
self._to_type_name = TypeNamer()

def generate(self) -> str:
if not self._m.arguments:
self._make_noargs()
else:
self._make_withargs()
return self._stream.getvalue()
return "\n".join(self.data)

def _get_common_elms(self) -> Tuple[List[_IdlFlagType], str, str]:
idlflags: List[_IdlFlagType] = []
Expand All @@ -268,7 +268,7 @@ def _make_noargs(self) -> None:
f" '{member_name}',\n"
" ),"
)
print(code, file=self._stream)
self.data.append(code)

def _make_withargs(self) -> None:
flags, type_name, member_name = self._get_common_elms()
Expand All @@ -278,10 +278,10 @@ def _make_withargs(self) -> None:
f" {type_name},\n"
f" '{member_name}',"
)
print(code, file=self._stream)
self.data.append(code)
arglist = [_to_arg_definition(*i) for i in self._iter_args()]
print(",\n".join(arglist), file=self._stream)
print(" ),", file=self._stream)
self.data.append(",\n".join(arglist))
self.data.append(" ),")

def _iter_args(self) -> Iterator[Tuple[str, str, List[str], _DefValType]]:
for typ, arg_name, _f, _defval in self._m.arguments:
Expand Down Expand Up @@ -342,15 +342,15 @@ def _iter_args(self) -> Iterator[Tuple[str, str, List[str], _DefValType]]:
class DispMethodGenerator(object):
def __init__(self, m: typedesc.DispMethod) -> None:
self._m = m
self._stream = io.StringIO()
self.data: List[str] = []
self._to_type_name = TypeNamer()

def generate(self) -> str:
if not self._m.arguments:
self._make_noargs()
else:
self._make_withargs()
return self._stream.getvalue()
return "\n".join(self.data)

def _get_common_elms(self) -> Tuple[List[_IdlFlagType], str, str]:
idlflags: List[_IdlFlagType] = []
Expand All @@ -372,7 +372,7 @@ def _make_noargs(self) -> None:
f" '{member_name}',\n"
" ),"
)
print(code, file=self._stream)
self.data.append(code)

def _make_withargs(self) -> None:
flags, type_name, member_name = self._get_common_elms()
Expand All @@ -382,10 +382,10 @@ def _make_withargs(self) -> None:
f" {type_name},\n"
f" '{member_name}',"
)
print(code, file=self._stream)
self.data.append(code)
arglist = [_to_arg_definition(*i) for i in self._iter_args()]
print(",\n".join(arglist), file=self._stream)
print(" ),", file=self._stream)
self.data.append(",\n".join(arglist))
self.data.append(" ),")

def _iter_args(self) -> Iterator[Tuple[str, str, List[str], _DefValType]]:
for typ, arg_name, idlflags, default in self._m.arguments:
Expand All @@ -409,7 +409,7 @@ def generate(self) -> str:
f" '{member_name}'\n"
" ),"
)
return code + "\n"
return code

def _get_common_elms(self) -> Tuple[List[_IdlFlagType], str, str]:
idlflags: List[_IdlFlagType] = []
Expand Down Expand Up @@ -1326,7 +1326,7 @@ def make_ComMethod(self, m: typedesc.ComMethod, isdual: bool) -> None:
if __debug__ and m.doc:
self.imports.add("comtypes", "helpstring")
gen = ComMethodGenerator(m, isdual)
print(gen.generate(), file=self.stream, end="")
print(gen.generate(), file=self.stream)
self.last_item_class = False
for typ, _, _, default in m.arguments:
if isinstance(typ, typedesc.ComInterface):
Expand All @@ -1344,7 +1344,7 @@ def make_DispMethod(self, m: typedesc.DispMethod) -> None:
if __debug__ and m.doc:
self.imports.add("comtypes", "helpstring")
gen = DispMethodGenerator(m)
print(gen.generate(), file=self.stream, end="")
print(gen.generate(), file=self.stream)
self.last_item_class = False
for _, _, _, default in m.arguments:
if default is not None:
Expand All @@ -1356,7 +1356,7 @@ def make_DispProperty(self, prop: typedesc.DispProperty) -> None:
if __debug__ and prop.doc:
self.imports.add("comtypes", "helpstring")
gen = DispPropertyGenerator(prop)
print(gen.generate(), file=self.stream, end="")
print(gen.generate(), file=self.stream)
self.last_item_class = False


Expand Down

0 comments on commit 455ac54

Please sign in to comment.