-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Add annotations to xml #5542
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Add annotations to xml #5542
Conversation
|
Updated annotation for While trying some things, I found that While the current |
src/robot/libraries/XML.py
Outdated
| class Element(Protocol): | ||
| tag: "bytes | str" | ||
|
|
||
| text: "None | str" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pekkaklarck text and tail can (per the xml.etree.ElementTree.Element documentation) contain arbitrary objects:
These attributes can be used to hold additional data associated with the element. Their values are usually strings but may be any application-specific object.
...
Applications may store arbitrary objects in these attributes.
This means that technically, the annotations here (and in all keywords related to text or tail) would have to be 'object'. At the same time, no tests fail on the current "None | str" annotations which indicates to me that we have no tests that check on handling "application-specific / arbitrary objects" in keywords. I also don't really see how working with arbitrary data for this would actually work. What do we want to do here?
|
Let's not make this complicated with Protocols. We are adding typing mainly for documentation purposes and partly to help Robot editord, the idea isn't, at least now, to do type checking. Complex types also don't help with the documentation goal, they just look confusing for non-technical users. I want to get RF 7.4 out soon. To keep this simple and to avoid wasting time, there are only two ways I see
If you want, you can experiment with Protocols and other ways to make typing better after the option 1. above is ready. If that brings concrete benefits, doesn't complicated code and doesn't make Libdoc documentation complicated, I can consider including it. I anyway want to be extremely clear that most likely such a PR will not be merged at least in RF 7.4 timeframe. My proposal how to move forward:
|
|
Ok, let's do that. I do believe that at least exploring Protocol with
the @runtime_checkable is worth some of our time since I think that if we
can support that, it'll be useful for library authors.
I'll see if I can update the PR tomorrow but I have a busy weekend ahead so
computer time may be very limited.
…On Thu, Nov 13, 2025 at 5:28 PM Pekka Klärck ***@***.***> wrote:
*pekkaklarck* left a comment (robotframework/robotframework#5542)
<#5542 (comment)>
Let's not make this complicated with Protocols. We are adding typing
mainly for documentation purposes and partly to help Robot editord, the
idea isn't, at least now, to do type checking. Complex types also don't
help with the documentation goal, they just look confusing for
non-technical users.
I want to get RF 7.4 out soon. To keep this simple and to avoid wasting
time, there are only two ways I see source can be annottated:
1. As Any. This is also the way I believe it should be annottated in
the beginning to get all the other annotations in.
2. As a custom Source class with a custom converter having
documentation that explains supported values. This would be good
considering the main goal is enhancing documentation. Type checkers may not
like it, but type checking isn't the goal so that's not a big problem.
If you want, you can experiment with Protocols and other ways to make
typing better after the option 1. above is ready. If that brings concrete
benefits, doesn't complicated code and doesn't make Libdoc documentation
complicated, I can consider including it. I anyway want to extremely clear
that most likely such a PR will not be merged at least in RF 7.4 timeframe.
My proposal how to move forward:
1. You create a PR with source: Any (or with source: Source where
Source is a type alias Source = Any).
2. I merge that PR.
3. You continue experimenting with better typing if you have interest
and don't mind if such enhancement may not be accepted.
4. I test how using a custom class with custom docs looks like.
5. I make a decision between Any, custom class and your possible PR
with enhanced typing.
—
Reply to this email directly, view it on GitHub
<#5542 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AK3CMZJWVRBG6OIOR67A6FT34SWUJAVCNFSM6AAAAACLZCFSB6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZTKMRYGYZTENJQGI>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
|
Subclassing This means mypy / pylance don't report anything meaningful, but I believe this is the most useful / clear for the users of the library / keyword docs. |
closes #5541