Comments (4)
Thanks for the response and the information. Hope the bug fix goes well
from robotframework.
I'm on mobile and cannot run the example now, but some clarifying questions below:
- Which Robot version do you use?
- Which conversations don't look good for you?
- Could you test changing
MyDictType
todict
in type hints?
from robotframework.
Thanks for the reply!
Which Robot version do you use?
pip show robotframework
Name: robotframework
Version: 7.0
Summary: Generic automation framework for acceptance testing and robotic process automation (RPA)
Home-page: https://robotframework.org
Author: Pekka Klärck
Author-email: [email protected]
License: Apache License 2.0
Location: /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages
Requires:
Required-by: robotframework-seleniumlibrary, robotframework-tidy
Which conversations don't look good for you?
Dict to str
I extracted the parts that do not look good. Where it's casting a dict
to a str
because the signature is def types_order_a(self, var: str | MyDictType | None | int):
, hence order_a being str
and not the Robot dict or native dict
I would expect it to not match on str but match on MyDictType. It does match for order_b
which puts MyDictType
first
expected | {'prop': 'bar'} | <class 'robot.utils.dotdict.DotDict'>
order_a | {'prop': 'bar'} | <class 'str'> ### This should not be str
order_b | {'prop': 'bar'} | <class 'robot.utils.dotdict.DotDict'>
expected | {'prop': 'bar'} | <class 'dict'>
order_a | {'prop': 'bar'} | <class 'str'> ### This should not be str
order_b | {'prop': 'bar'} | <class 'dict'>
Float to str
There is also the issue with float, where I expect there to be an error instead of a cast from float to str
expected | 2.0 | <class 'float'>
order_a | 2.0 | <class 'str'> ### This should be float
order_b | 2.0 | <class 'str'> ### This should be float
Could you test changing MyDictType to dict in type hints?
i did so and it works as expected
expected | {'prop': 'bar'} | <class 'robot.utils.dotdict.DotDict'>
order_a | {'prop': 'bar'} | <class 'robot.utils.dotdict.DotDict'>
order_b | {'prop': 'bar'} | <class 'robot.utils.dotdict.DotDict'>
expected | {'prop': 'bar'} | <class 'dict'>
order_a | {'prop': 'bar'} | <class 'dict'>
order_b | {'prop': 'bar'} | <class 'dict'>
Im not sure why the TypedDict is causing this error but I have not looked deeply into it and just removed the type from my library to solve this issue
from robotframework.
If an argument has multiple accepted types, argument conversion goes like this on high level:
- Check does the given argument match any of the accepted types.
- If it does, use the argument as-is.
- If it doesn't, try converting the argument to specified types from left to right.
- If conversion to any type succeeds, return the converted value.
- If no conversion succeeds, fail.
The above rules explain why your float is converted to a string:
- Your keyword doesn't accept floats
- Float thus cannot be used as-is.
- Conversion to specified types is attempted.
- Conversion to
str
succeeds and the converted value is returned.
The problems with TypedDicts are caused by a bug, though. When checking does the given argument match any of the accepted types, TypedDicts currently never match. Because no other type match either, conversion is attempted from left to right and str
conversion is the first to succeed. As you have already noticed, if you have str
after a TypedDict, TypedDict conversion is attempted first and it succeeds.
I'll update the issue title accordingly. Fixing this doesn't seem to be too complicated, so I'll assign this to already long overdue 7.0.1 scope.
from robotframework.
Related Issues (20)
- Feature request: rebot - Option to embed images in html HOT 4
- Feature request: Log stack trace for each faliure HOT 1
- How to register a customize logger with the robot.output.logger in Robot 7.x HOT 1
- Named-only arguments are not trace logged with user keywords HOT 1
- Collections: Value of `ignore_case` argument accidentally logged HOT 1
- Remove confusing debug statement HOT 1
- Error Encountered When Running BDD Example (https://docs.robotframework.org/docs/testcase_styles/bdd) HOT 3
- Add new section about style to User Guide HOT 1
- Add support for time strings containing "week" values HOT 2
- Extended variable syntax does not take effect HOT 1
- Logging doesn't work propertly if Robot is running on thread HOT 4
- list the IP addresses of all connected devices HOT 1
- Embedded argument support for examples in libdoc
- Python global variables not visible if class is created HOT 1
- ExecutionResult is returning a wrong start_time, end_time and elapsed. HOT 5
- Support using named arguments with non-string values programmatically HOT 1
- Support keyword aliases HOT 4
- Warning with page screen shot HOT 1
- More events for Listener interface ? HOT 1
- Update Dutch language file
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from robotframework.