This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Petter S
Recipients Petter S, xtreak
Date 2019-01-08.11:07:48
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1546945668.24.0.684739181753.issue35656@roundup.psfhosted.org>
In-reply-to
Content
Yes, something like this:

    class APPROXIMATE:
        """Takes a floating point number and implements approximate equality."""

        def __init__(self, value):
            self.value = value

        def __eq__(self, other):
            return abs(self.value - other) / (abs(self.value) + abs(other)) < 1e-6

        def __repr__(self):
            return f"APPROXIMATE({self.value})"


Then the following would hold:

    got = {
    "name": "Petter",
    "length": 1.900001
    }

    expected = {
    "name": "Petter",
    "length": APPROXIMATE(1.9)
    }

    assert got == expected

But not

    got["length"] = 1.8
    assert got == expected
History
Date User Action Args
2019-01-08 11:07:49Petter Ssetrecipients: + Petter S, xtreak
2019-01-08 11:07:48Petter Ssetmessageid: <1546945668.24.0.684739181753.issue35656@roundup.psfhosted.org>
2019-01-08 11:07:48Petter Slinkissue35656 messages
2019-01-08 11:07:48Petter Screate