Skip to content

[Bug]: Boolean values are incorrectly accepted by integer and float validators #258

Closed

Description

@sepandhaghighi

Contact details

No response

What happened?

The Response class uses _validate_non_negative_int() and _validate_non_negative_float() to validate integer and float parameters. However, these validators use isinstance(value, int) and isinstance(value, (float, int)).

Because bool is a subclass of int in Python, boolean values such as True and False pass these validations.

As a result, parameters that are expected to be integers or floats can incorrectly accept boolean values.

Steps to reproduce

  1. Create a Response object with a boolean value for an integer parameter:
Response(top_k=True)
  1. Create a Response object with a boolean value for a float parameter:
Response(temperature=True)
  1. Similarly, boolean values can be passed to:
Response(score=True)
Response(top_p=False)
Response(inference_time=True)
Response(tokens=False)

Expected behavior

Boolean values should be rejected when an integer or float value is expected.

For example:

Response(top_k=True)

should raise MemorValidationError rather than accepting True as the integer 1.

Actual behavior

Boolean values are accepted as valid integer/float inputs because Python considers bool a subclass of int.

Operating system

Linux

Python version

Python 3.11

Memor version

Memor 1.3

Relevant log output

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

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions