Urgent.News

What's breaking now, across thousands of outlets.

Tech

Three convincing Python fixes that still fail the boundary case

A fix can remove the first failure and still violate the contract. Here are three small examples where the attempted repair looks reasonable until you run the boundary checks. These examples come from Failure Map, a project I created. They are controlled Python models with explicit contracts, not reports of production incidents. The programs below use only the standard library. 1. Deduplicating…

The article "Three convincing Python fixes that still fail the boundary case" discusses three examples of Python code that appear to work correctly but fail when tested against specific boundary cases. The first example involves deduplicating values instead of events, where the intended contract is to count each event identity once while preserving distinct events with equal amounts.

The attempted repair uses a set to deduplicate amounts, but this fails to account for the fact that two events with the same amount are still distinct events. The second example deals with moving an expiration boundary by a whole tick, where the contract states that an entry is valid before its expiration instant and invalid at that instant.

The attempted repair overcorrects by checking if the current time is less than the expiration time minus one, which fails for timestamps that are not whole numbers. The third example involves making pagination inclusive to recover ties, where the contract requires filtering based on a primary key and a unique identifier. The attempted repair changes the operator to make pagination inclusive, but this fails to account for the fact that it may skip certain records.

Brief written by urgent.news from Dev.to's own syndicated text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

Movies and Series Every Programmer Should Watch

1. Mr. Robot 2015–2019 — Series IMDb: ⭐ 8.5/10 Rotten Tomatoes: 🍅 94% Genre: Drama, Crime, Cybersecurity Mr. Robot follows Elliot Alderson, a cybersecurity engineer and hacker who becomes involved…

More from Thursday 1 October →