Skip to content

[SOLVED] TypeError: '<=' not supported between instances of 'int' and 'str' in Percentage.py #110

@sajho-dk

Description

@sajho-dk

Hi, I realized that there is an issue in 'validate(self, value)' of code/Attack/ParameterTypes/Percentage.py. I have corrected the issue and commented the line with the error.

from Attack.ParameterTypes.BaseType import ParameterType


class Percentage(ParameterType):

    def __init__(self):
        super(Percentage, self).__init__()
        self.name = "Percentage"

    def validate(self, value) -> (bool, int):
        #return Percentage._is_float(value)[0] and 0 <= value <= 1, value
        res = Percentage._is_float(value)
        return res[0] and 0 <= res[1] <= 1, res[1]

    @staticmethod
    def _is_float(value):
        """
        Checks whether the given value is a float.

        :param value: The value to be checked.
        :return: True if the value is a float, otherwise False. And the casted float.
        """
        try:
            value = float(value)
            return True, value
        except ValueError:
            return False, value

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions