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
The main benefit is getting automatic completion by IDEs.
Because visitors can be used both with robot.running and robot.result models, the documentation should mention that concrete visitor implementations may want to import more detailed types:
This ought to be so easy that can be easily done in RF 6.1. Adding needed imports to the top of the module is likely to create a circular import, but we can avoid that by using if TYPE_CHECKING.
Type hints added by the commit above. Needed to use if TYPE_HINTING with some imports and that then required using forwards references (i.e. strings) like 'TestSuite'instead of actual classes. A bit annoying but not much we can do about that. Having TestSuite import behind if TYPE_HINTING also makes Sphinx to throw some errors due to it getting confused where TestSuite actually is imported from. Seems to be a known issue in Sphinx so nothing we can do about that either. Anyway, the results look pretty good and I believe type hints in public APIs like this are useful.
Because visitors can be used both with running and result suite models, the types used in type hints are common base classes in robot.model. I added a separate section about type hints to the visitor API docs, and mentioned that when creating visitors, you may want to import more detailed types from robot.running.model or robot.result.model. I initially wrote that you can import them from robot.running or robot.result, but I then noticed that only TestSuite and some other top level classes were exposed on that level and majority actually needs to be imported from the robot.xxx.model submodule.
The question is, should we expose all running and result model objects directly from robot.running and robot.result package level? My first thought was that it would be a good idea, but after thinking this a bit more I don't see much/any harm in requiring imports from the model submodule. That's a bit more explicit than importing from the package level, and exposing all model objects, there are many, on the package level could add quite a lot of noise.
@yanne and I discussed about this and agreed that it's enough that running and result model objects are exposed via robot.running.model and robot.result.model, respectively. I'll enhance the docstrings of these modules a bit to make that explicit.
With listener v3 we need both running and result objects in the signature, and when implementing #4568 it turned out the best way to type that is def start_suite(data: running.TestSuite, result: result.TestSuite). To be able to use this approach with all model objects, it's best to expose all of them via robot.running and robot.result. It also turned out that we already do that with robot.result. Need to do that with robot.running as well. Documentation related to this needs to be updated as well.
Activity
Add type hints to visitor API #4569
pekkaklarck commentedon Feb 14, 2023
Type hints added by the commit above. Needed to use
if TYPE_HINTINGwith some imports and that then required using forwards references (i.e. strings) like'TestSuite'instead of actual classes. A bit annoying but not much we can do about that. HavingTestSuiteimport behindif TYPE_HINTINGalso makes Sphinx to throw some errors due to it getting confused whereTestSuiteactually is imported from. Seems to be a known issue in Sphinx so nothing we can do about that either. Anyway, the results look pretty good and I believe type hints in public APIs like this are useful.pekkaklarck commentedon Feb 14, 2023
Because visitors can be used both with running and result suite models, the types used in type hints are common base classes in
robot.model. I added a separate section about type hints to the visitor API docs, and mentioned that when creating visitors, you may want to import more detailed types fromrobot.running.modelorrobot.result.model. I initially wrote that you can import them fromrobot.runningorrobot.result, but I then noticed that onlyTestSuiteand some other top level classes were exposed on that level and majority actually needs to be imported from therobot.xxx.modelsubmodule.The question is, should we expose all running and result model objects directly from
robot.runningandrobot.resultpackage level? My first thought was that it would be a good idea, but after thinking this a bit more I don't see much/any harm in requiring imports from themodelsubmodule. That's a bit more explicit than importing from the package level, and exposing all model objects, there are many, on the package level could add quite a lot of noise.pekkaklarck commentedon Feb 14, 2023
@yanne and I discussed about this and agreed that it's enough that running and result model objects are exposed via
robot.running.modelandrobot.result.model, respectively. I'll enhance the docstrings of these modules a bit to make that explicit.pekkaklarck commentedon Feb 16, 2023
With listener v3 we need both running and result objects in the signature, and when implementing #4568 it turned out the best way to type that is
def start_suite(data: running.TestSuite, result: result.TestSuite). To be able to use this approach with all model objects, it's best to expose all of them viarobot.runningandrobot.result. It also turned out that we already do that withrobot.result. Need to do that withrobot.runningas well. Documentation related to this needs to be updated as well.Expose robot.running.model classes via robot.running.
Add type hints to visitor API #4569
API doc enhancements.
Expose robot.running.model classes via robot.running.