Skip to content

Unknown format code 'f' for object of type 'str' ... if bool with str is compared #200

@d0b3rm4n

Description

@d0b3rm4n

Describe the bug
Since isinstance(True, int) is true, and int is in the list of numbers in

deepdiff/deepdiff/diff.py

Lines 1155 to 1156 in 4662fae

elif isinstance(level.t1, numbers):
self.__diff_numbers(level)
it runs the "number" diff code if in the first dict the value is of type bool, but if the 2nd compared value is not a number type or bool, e.g. str it fails later on, when trying to apply the format code.

To Reproduce

import deepdiff
foo = {'foobar': True}
bar = {'foobar': 'No'}
deepdiff.DeepDiff(foo, bar, ignore_type_in_groups=[(bool, str)], ignore_numeric_type_changes=True)

Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "C:\Users\DEVEL\venvs\global_default\lib\site-packages\deepdiff\diff.py", line 259, in __init__
    self.__diff(root, parents_ids=frozenset({id(t1)}), _original_type=_original_type)
  File "C:\Users\DEVEL\venvs\global_default\lib\site-packages\deepdiff\diff.py", line 1159, in __diff
    self.__diff_dict(level, parents_ids)
  File "C:\Users\DEVEL\venvs\global_default\lib\site-packages\deepdiff\diff.py", line 492, in __diff_dict
    self.__diff(next_level, parents_ids_added)
  File "C:\Users\DEVEL\venvs\global_default\lib\site-packages\deepdiff\diff.py", line 1156, in __diff
    self.__diff_numbers(level)
  File "C:\Users\DEVEL\venvs\global_default\lib\site-packages\deepdiff\diff.py", line 1003, in __diff_numbers
    number_format_notation=self.number_format_notation)
  File "C:\Users\DEVEL\venvs\global_default\lib\site-packages\deepdiff\helper.py", line 343, in number_to_string
    result = (using % significant_digits).format(number)
ValueError: Unknown format code 'f' for object of type 'str'

Expected behavior
I would it expect to skip over and inform that bool True is not equal to str No.

OS, DeepDiff version and Python version (please complete the following information):

  • OS: Win10
  • Version:
    • Python: 3.7.5
    • Deepdiff: 5.0.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions