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 p-ganssle
Recipients ammar2, p-ganssle, serhiy.storchaka
Date 2020-12-16.17:07:26
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1608138446.98.0.251120235022.issue42660@roundup.psfhosted.org>
In-reply-to
Content
> Just my two cents, this isn't just "some compilers". Everything from gcc, msvc, C# to the rust compiler complain about this sort of code. As they should, this is effectively dead code.

They complain because most of the time it's a sign that people were intending to use a signed integer, and it's an indicator that they may be susceptible to integer overflow.

In this case, it was a deliberate choice to include the extra check knowing it's dead code, because it is essentially a machine-checked documentation of the bounds of that particular variable.


> I think the more pragmatic way to enforce and document this assumption would be to have a unit test that actually checks that the constructor fails with "negative" days. It'll continue to fail right now as its interpretation as an unsigned int will be large and it will start failing if someone changes this to a signed type.

This would be helpful, but it's not an either-or situation. This particular thing would be tricky to write a targeted unit test for, because it's a very deep implementation detail. Such a unit test would also be quite physically separated from the code in question, whereas if we left the code as-is, we'd never see this type of bug, and if we added a static assertion we'd be told at compile time exactly what is wrong.

The biggest problem here is the fact that we cannot disable compiler warnings when complying with them makes the code less readable and/or less robust. This makes compiler warnings less useful, since it changes the calculus around whether or not it's worth it to introduce a new compiler warning.
History
Date User Action Args
2020-12-16 17:07:27p-gansslesetrecipients: + p-ganssle, serhiy.storchaka, ammar2
2020-12-16 17:07:26p-gansslesetmessageid: <1608138446.98.0.251120235022.issue42660@roundup.psfhosted.org>
2020-12-16 17:07:26p-gansslelinkissue42660 messages
2020-12-16 17:07:26p-gansslecreate