weiwei / junitparser

Parses JUnit/xUnit Result XML files with ease
https://junitparser.readthedocs.io
Other
120 stars 52 forks source link

Incorrect type annotation? #133

Closed dyollb closed 3 months ago

dyollb commented 3 months ago

Pyright complains when I try to set the result property of a TestCase.

I think the type annation of value should be list[Result] https://github.com/weiwei/junitparser/blob/d2b7796af4ec12a623487f7f7c0b3c0d72db2404/junitparser/junitparser.py#L367

or the code could handle list/Result values, e.g., something like

    @result.setter
    def result(self, value: Result | list[Result]):
        # First remove all existing results
        for entry in self.result:
            if any(isinstance(entry, r) for r in POSSIBLE_RESULTS):
                self.remove(entry)
        values = [value] if isinstance(value, Result) else value
        for entry in values:
            if any(isinstance(entry, r) for r in POSSIBLE_RESULTS):
                self.append(entry)

I am using python 3.11, latest junitparser from pypi.