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 TestSuite structure would benefit from more type hints that would allow IDEs to provide better completion support. That would help with writing code using the visitor API and listener API v3, especially if #4569 and #4568 are implemented.
For most parts adding type info ought to be pretty easy and at least those parts should preferably be done already in RF 6.1. It is possible that TestSuite code using our @setter is too dynamic to editors to understand and just adding type info to isn't enough. If that's the case, we need to consider changing such code so that it uses the standard @property.setter instead. That may be too big a task for RF 6.1, though.
I added Mypy compatible type hints to our setter in 810afc8. Based on discussion our Slack with @Serhiy1, that helps also with VSCode that uses pyrigh. Typing can be still enhanced (should at least use setter(Generic[T, V]) instead of setter(Generic[V])), but this is a good start nevertheless.
Unfortunately the added typing didn't help at all with PyCharm and I submitted issue PY-59658 about that to their tracker. That issue was closed as a duplicate of PY-29523 and there seemed to be also other related issues.
PyCharm also has problems with descriptors being used together with __slots__. Basically when we use __slots__ and have a descriptor like
then assignment like self.source = source in __init__ cause errors. I was about to submit an issue about that as well, but it turned out that there's already PY-29770 about that.
I'm not surprised with PyCharm having bugs, but it's pretty worrying that both PY-29523 and PY-29770 have been reported already five years ago and there hasn't been much interest towards them. We cannot thus expect them to be fixed in the near future. If you are PyCharm user and interested in better experience when developing Robot Framework or tooling using its APIs, I recommend you to vote the referenced issues. You need to log in to Youtrack to vote, but you can authenticate using your GitHub account. I don't have high hopes for voting to help, but there's not much else we can do.
@Serhiy1 and I have been working hard to get proper type hinting to the whole TestSuite structure. The challenge has been that we have robot.running.TestSuite structure, robot.result.TestSuite structure, and their base classes in robot.model.TestSuite structure. The common functionality is naturally implemented in robot.model, and getting typing to work with extending classes was challenging. Another challenge is that RF 6.1 still support Python 3.6.
After all the hard work typing now works pretty well. For example, when the following code is opened in VSCode, it shows correct intellisense for all objects:
As I mentioned above, PyCharm unfortunately has issues with typing and intellisense in the above example doesn't work at all. There's not much else we can do that hope they get the biggest issues fixed at some point.
After the latest changes @Serhiy1 and I consider TestSuite typing to be in good enough shape for RF 6.1. We already have some ideas how to enhance it in the future when we don't anymore need to care about Python 3.6 and 3.7, though.
Activity
Add type hints to `setter`.
Add type hints to `setter`.
Add type hints to `setter`.
Add type hints to `setter`.
pekkaklarck commentedon Mar 21, 2023
I added Mypy compatible type hints to our
setterin 810afc8. Based on discussion our Slack with @Serhiy1, that helps also with VSCode that uses pyrigh. Typing can be still enhanced (should at least usesetter(Generic[T, V])instead ofsetter(Generic[V])), but this is a good start nevertheless.Unfortunately the added typing didn't help at all with PyCharm and I submitted issue PY-59658 about that to their tracker. That issue was closed as a duplicate of PY-29523 and there seemed to be also other related issues.
PyCharm also has problems with descriptors being used together with
__slots__. Basically when we use__slots__and have a descriptor likethen assignment like
self.source = sourcein__init__cause errors. I was about to submit an issue about that as well, but it turned out that there's already PY-29770 about that.I'm not surprised with PyCharm having bugs, but it's pretty worrying that both PY-29523 and PY-29770 have been reported already five years ago and there hasn't been much interest towards them. We cannot thus expect them to be fixed in the near future. If you are PyCharm user and interested in better experience when developing Robot Framework or tooling using its APIs, I recommend you to vote the referenced issues. You need to log in to Youtrack to vote, but you can authenticate using your GitHub account. I don't have high hopes for voting to help, but there's not much else we can do.
Enhance `setter` typing and documentation.
Make ItemList generic. Part of #4570.
pekkaklarck commentedon Apr 4, 2023
Type hints added to
robot.model.testsuiteby @Serhiy1 in 984c2e1 (PR #4678).More type hints to robot.model.TestSuite and elsewhere.
TestSuite typing tuning. #4570
4 remaining items
ModelObject enhancements
Enhance `robot.model.control`.
Type hint enhancements related to #4570.
Add typing to robot.running.model. Part of #4570.
Make model.BaseBody accept Generic parameters (#4766)
Add typing to `robot.result.model`. Part of #4570.
Enhance model.branches and result.Iterations typing (#4767)
Make fixture generic to enable type hinting (#4770)
Enhance setup and teardown typing for TestSuite and TestCase (#4773)
pekkaklarck commentedon May 31, 2023
@Serhiy1 and I have been working hard to get proper type hinting to the whole
TestSuitestructure. The challenge has been that we haverobot.running.TestSuitestructure,robot.result.TestSuitestructure, and their base classes inrobot.model.TestSuitestructure. The common functionality is naturally implemented inrobot.model, and getting typing to work with extending classes was challenging. Another challenge is that RF 6.1 still support Python 3.6.After all the hard work typing now works pretty well. For example, when the following code is opened in VSCode, it shows correct intellisense for all objects:
As I mentioned above, PyCharm unfortunately has issues with typing and intellisense in the above example doesn't work at all. There's not much else we can do that hope they get the biggest issues fixed at some point.
After the latest changes @Serhiy1 and I consider
TestSuitetyping to be in good enough shape for RF 6.1. We already have some ideas how to enhance it in the future when we don't anymore need to care about Python 3.6 and 3.7, though.Huge thanks for your help @Serhiy1!