
Aug. 18, 2023
9:07 a.m.
On Fri, 18 Aug 2023 at 08:35, Ran Benita via Typing-sig < typing-sig@python.org> wrote:
The traditional way plugins did this was to use an attribute on the `item`:
def pytest_runtest_setup(item: pytest.Item) -> None: item.my_plugin_attr = MyPluginAttrType(...)
def pytest_runtest_teardown(item: pytest.Item) -> None: use_my_attr(item.my_plugin_attr) # Maybe del item.my_plugin_attr
The problem with this is that type checkers are not aware of `my_plugin_attr` and they complain. To make things clean for type checkers, and type safe (no casts/asserts) an alternative solution is needed.
This sounds very much like `types.SimpleNamespace`. So maybe you could look at how typeshed annotates that type? Paul