Skip to content

Add type hints to standard libraries #5373

Closed
4 of 4 issues completed
Closed

Description

@robinmackaij

As discussed here.

This issue is the parent issue to track progress on all the standard libraries (sub-issues).

Overall implementation decisions can be discussed / recorded here.

The Python typing best practices can be found here:
https://typing.python.org/en/latest/reference/best_practices.html

Sub-issues

Sub-issues

4 of 4 Issues completed
Loading 4 sub-issues

Activity

  1. twbecker commented on Mar 20, 2025

    @twbecker

    Came here looking for this. I'd been experimenting with custom argument converters and was disappointed to see that they aren't invoked for standard keywords because there are no type hints. Am I correct in assuming that this would correct that?

  2. added this to the v7.3 milestone on Mar 27, 2025
  3. pekkaklarck commented on Mar 27, 2025

    @pekkaklarck
    Member

    @twbecker Standard libraries predate all automatic argument conversion support so they needed to implement their own argument conversion. All that custom code can be removed when we add type hints, but that probably doesn't bring any concrete benefits for normal users. Libdoc documentation getting better is nice, though.

  4. pekkaklarck commented on Apr 7, 2025

    @pekkaklarck
    Member

    In order to get RF 7.3 out soon, I move this issue to RF 7.4 scope. It would still be possible to add type hints to some library or libraries in RF 7.3, though. My plan is to get RF 7.3 release candidate out early next week and that's a deadline for all code changes (which includes annotations). Are there any libraries you'd like to work on in that time frame @robinmackaij? If there are, please submit separate issues for each library and I can add them to RF 7.3 scope.

  5. modified the milestones: v7.3, v7.4 on Apr 7, 2025
  6. robinmackaij commented on Apr 7, 2025

    @robinmackaij
    ContributorAuthor

    Are there any libraries you'd like to work on in that time frame @robinmackaij? If there are, please submit separate issues for each library and I can add them to RF 7.3 scope.

    I need to work on training-related material at the moment and I also need to work towards an OpenApiTools release, so I have little time to work on this atm. It'd be good to get the sub-issues in the tracker when 7.3 is out, then it's easier to keep track and create the PRs (especially if there's others interested in contributing to this and we need to coordinate on the effort).

  7. pekkaklarck commented on Apr 24, 2025

    @pekkaklarck
    Member

    Some keywords accepting configuration parameters as **config instead of named-only arguments makes adding type hints to them annoying. The reason to use **config is Python 2 support, so these keywords can be updated. I submitted #5412 about that and try to get it done still in RF 7.3 timeline.

  8. changed the title [-]Add annotations / type hints to the standard libraries[/-] [+]Add type hints to the standard libraries[/+] on Apr 24, 2025
  9. pekkaklarck commented on Jun 19, 2025

    @pekkaklarck
    Member

    Also return type hints should be added where applicable.

  10. silentw0lf commented on Aug 17, 2025

    @silentw0lf
    Contributor

    @robinmackaij I would be interested to work on it too.

    Any updates for coordination?

  11. silentw0lf commented on Aug 17, 2025

    @silentw0lf
    Contributor

    Libraries would be (vias docs):
    (x) BuiltIn.py
    (x) Collections.py
    (x) DateTime.py
    (x) Dialogs.py
    (x) OperatingSystem.py
    (x) Process.py
    (x) Screenshot.py
    (x) String.py
    (x) Telnet.py
    (x) XML.py

    I do not know how to create sub-issues here (probably no permissions).
    I will start working on 1 library for the beginning: DateTime.py .

  12. 49 remaining items

  13. silentw0lf commented on Nov 20, 2025

    @silentw0lf
    Contributor

    I will look into the MR for Strings now: #5554

    by reading through our discussions above, I see the the following tasks:

    • Remove check within function that test differnt type (than in param, andthen raise) + there tests
    • remove @keyword(types=None) since types provided
    • backwards compatibility (potentially > 30 functions)
      • provide param str | bytes args where possible (i have to check for each parameter, if the functions in the keyword can also be called on a buytes objects - no quick job)
      • add tests too (i hope this will not take forever, will only include basics)
      • (no code changes to add bytes support (stay with str))
    • Literal support (see DateTime)
    • Adding a note like "Some keywords also work with bytes in addition to strings."
  14. silentw0lf commented on Nov 20, 2025

    @silentw0lf
    Contributor

    A hint for: Dialogs (@pekkaklarck)

    I also implemnted typing for diaglogs but forgot to push it. Even if it seemed to be quiet easy/straigt forward, there was a problem in atests (manuel GUI dialog tests). Something seemed incorrect there. If I remember correctly, some value in a diaglog that should have been hidden was exposed, or the other way around? Maybe you could double check that. :)

    my old changes/commit:
    silentw0lf@e206cc0
    (but maybe I just did something incorrectly for implementation)

  15. silentw0lf commented on Nov 20, 2025

    @silentw0lf
    Contributor

    I will look into the MR for Strings now: #5497

    by reading through our discussions above, I see the the following tasks:

    • Remove check within function that test differnt type (than in param, andthen raise) + there tests[x] remove @keyword(types=None) since types provided* [ ] backwards compatibility (potentially > 30 functions)

      • provide param str | bytes args where possible (i have to check for each parameter, if the functions in the keyword can also be called on a buytes objects - no quick job)* add tests too (i hope this will not take forever, will only include basics)* (no code changes to add bytes support (stay with str))[x] Literal support (see DateTime)[ ] Adding a note like "Some keywords also work with bytes in addition to strings."

    rebased upstream/master and pushed commits: #5554

    @pekkaklarck) I have implemented the tasks as far as I can. Problems remain with bytes support. Where I couldn't make a decision myself, I added a TODO(@pekkaklarck) to the functions with information.

    The problem concerns backwards compatibility for keywords. Either

    [1] You allow bytes—then a test function must truly support it (which is particularly difficult when there are 2-3 parameters that can each be either bytes or str influencing each other during code paths; in many cases that's simply not possible -> high risk for bugs).

    [2] You don't allow bytes, because you can't support all parameter combinations—however, this would break older Robot versions if a user happened to use the one parameter combination that used to work (other type combinations would also then not work).

    [3] Where bytes can't be safely introduced 100%, we can leave it as str, and there will be a few special cases where backwards compatibility cannot be maintained.

    Could you perhaps adjust the remaining places according to your preferences in the MR?
    Otherwise, I think the discussions will drag on for a long time back and forth, even though the implementation is already 95% finished.

    local latests and utests PASS but there is some empty error porblem in the pipeline:

    Image
  16. pekkaklarck commented on Nov 21, 2025

    @pekkaklarck
    Member

    Quick comments about String and other topics mentioned above.

  17. pekkaklarck commented on Nov 27, 2025

    @pekkaklarck
    Member

    XML is in! Thanks @robinmackaij!

    The last one is String. I'll review the PR next @silentw0lf, but I won't have time for it today.

  18. pekkaklarck commented on Nov 28, 2025

    @pekkaklarck
    Member

    @silentw0lf, I reviewed this String PR. Do you have idea when you'd have time to look at the comments? I'd like to get the PR closed soonish so that I can finish #5537 and #5548 that are dependent on it.

  19. pekkaklarck commented on Dec 1, 2025

    @pekkaklarck
    Member

    String got typing in PR #5554 by @silentw0lf. Thanks for the contribution!

    String typing may still change as part of #5548, but the library now has typing so I closed #5558. Now all libraries that we wanted to add typing have them, so also this issue can be finally closed.

    Thanks all who participated! I knew this was going to be a big task, but it turned out to be even bigger than I anticipated. Had I known how much work this is, I'd probably moved this to RF 7.5 or only covered some libraries now. Anyway, the results are good so we should be proud!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions