metomi/isodatetime

date_string referenced before assignment

kinow opened this issue · 2 comments

kinow commented

A user can programmatically set certain values to None, causing a runtime error in the API. Example test case here: kinow@2e05d90

Here's the same code from the commit above

    def test_timepoint_dump_format(self):
        """Test the timepoint format dump when values are programmatically set to None"""
        t = data.TimePoint(year="1984")
        # commenting out month_of_year here is enough to make the test pass
        t.month_of_year = None
        t.day_of_year = None
        t.week_of_year = None
        self.assertEqual("1984-01-01T00:00:00Z", t.__str__())

I believe while a user may not have the need nor intention to set these values to None, it may still happen when using the API in another software.

So I think maybe we could raise an error in the _get_truncated_dump_format if we were not able to create date_string, or find another way to prevent the invalid runtime state.

Bruno

@kinow Is #118 not sufficient to fix this?

kinow commented

Oh, it is!