Giter Club home page Giter Club logo

Comments (4)

David-Tennant-Enreach avatar David-Tennant-Enreach commented on June 16, 2024 1

Thanks for the response and the information. Hope the bug fix goes well

from robotframework.

pekkaklarck avatar pekkaklarck commented on June 16, 2024

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 to dict in type hints?

from robotframework.

David-Tennant-Enreach avatar David-Tennant-Enreach commented on June 16, 2024

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.

pekkaklarck avatar pekkaklarck commented on June 16, 2024

If an argument has multiple accepted types, argument conversion goes like this on high level:

  1. Check does the given argument match any of the accepted types.
  2. If it does, use the argument as-is.
  3. If it doesn't, try converting the argument to specified types from left to right.
  4. If conversion to any type succeeds, return the converted value.
  5. If no conversion succeeds, fail.

The above rules explain why your float is converted to a string:

  1. Your keyword doesn't accept floats
  2. Float thus cannot be used as-is.
  3. Conversion to specified types is attempted.
  4. 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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.