From f38c653a75492a8ec1fd95b1aa148aea13689ec3 Mon Sep 17 00:00:00 2001 From: Eli Schwartz Date: Sun, 11 Jun 2023 23:26:17 -0400 Subject: [PATCH] backends/xcode: simplify an obviously too-complicated function This function has a pretty unique name, and a simple grep shows that it is only ever called as: ``` add_comment(PbxComment('...........')) ``` It doesn't need to include logic such as handling str. Moreover it looks like that handling was broken anyway... it handled the case where comment is type str, by constructing a new PbxComment(str) instead of PbxComment(comment), a condition that cannot ever be valid (and crashed due to other assertions). Fixes: mesonbuild/backend/xcodebackend.py:148:42: error: Argument 1 to "PbxComment" has incompatible type "type[str]"; expected "str" [arg-type] --- mesonbuild/backend/xcodebackend.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/mesonbuild/backend/xcodebackend.py b/mesonbuild/backend/xcodebackend.py index 958465f90..9c88eecb4 100644 --- a/mesonbuild/backend/xcodebackend.py +++ b/mesonbuild/backend/xcodebackend.py @@ -138,12 +138,9 @@ class PbxDict: def has_item(self, key): return key in self.keys - def add_comment(self, comment: T.Union[str, PbxComment]) -> None: - if isinstance(comment, str): - self.items.append(PbxComment(str)) - else: - assert isinstance(comment, PbxComment) - self.items.append(comment) + def add_comment(self, comment: PbxComment) -> None: + assert isinstance(comment, PbxComment) + self.items.append(comment) def write(self, ofile: T.TextIO, indent_level: int) -> None: ofile.write('{\n')