You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Type checkers report the type of TestReport.when as Union[builtins.str, None] (coming from the BaseReport base class) rather than the correct type for TestReport of Literal["setup", "call", "teardown"].
(I checked this with mypy 1.10.0 and pyright 1.1.342)
This looks to be due to the fact that the BaseReport annotation is on a class attribute, which takes precedence over the instance attribute assigned within the derived TestReport class.
Type checkers report the type of
TestReport.when
asUnion[builtins.str, None]
(coming from theBaseReport
base class) rather than the correct type forTestReport
ofLiteral["setup", "call", "teardown"]
.(I checked this with
mypy
1.10.0 andpyright
1.1.342)This looks to be due to the fact that the
BaseReport
annotation is on a class attribute, which takes precedence over the instance attribute assigned within the derivedTestReport
class.Repro
mypy 1.10.0 reports:
(The actual type is
Literal["setup", "call", "teardown"]
)Suggested Solution
I think this can be resolved by adding a class-level type annotation to
TestReport
with the narrower type (the same applies tolocation
):The text was updated successfully, but these errors were encountered: