ScreenPyHQ / screenpy

Screenplay pattern base for Python automated UI test suites.
MIT License
28 stars 4 forks source link

Inherited Pause in screenpy-selenium has errors in mypy #25

Closed MarcelWilson closed 1 year ago

MarcelWilson commented 2 years ago

screenp-selenium has a Pause class that inherits screenpy.actions.pause.Pause.

mypy will error on the following code from screenpy-selenium

Pause.for_(length).seconds_because("... reasons").add_to_chain(tester, chain)

"Pause" has not attribute "add_to_chain" [attr-defined]

MarcelWilson commented 2 years ago

The problem exists for any baseclass that annotates itself as the object returned by a method.
The easy solution to this would be to create TypeVars for each baseclass that would potentially be inherited.

MarcelWilson commented 2 years ago

See Mypy docs for more details about how TypeVar is used.

MarcelWilson commented 2 years ago

PEP 673 was accepted and is included in 3.11 but mypy still hasn't merged the update to support checking it. I'm proposing we add TypeVar now and when https://github.com/python/mypy/pull/11666 eventually releases I'll update the package to utilize Self

perrygoy commented 1 year ago

Thanks to @bandophahita's hard work, this issue has been resolved!