Lesson map
Lesson 06. Map, example, EX052.
flowchart TD
S["A version string"] --> T["Split on dots, then int"]
T --> C{"Is the installed tuple less than the fixed tuple?"}
C -->|Yes| U["Append UPDATE"]
C -->|No| N["No update note from this test"]
The comparison is numeric tuples. It is not dictionary order on the raw text.
Logical drawing
installed donate-form: (3, 2, 0)
fixed donate-form: (3, 2, 4)
(3, 2, 0) < (3, 2, 4) is true
string order of 3.10 and 3.9 is a different test, and neither string is in this list
Learning outcomes
After this chapter, you should be able to:
- Explain
vas a split into integers. - Show why
(3, 2, 0)is less than(3, 2, 4). - Refuse a string-order claim about versions this file does not contain.
6.1 v splits, maps to int, and compares the tuples.
The helper is tuple(map(int, s.split("."))). 3.2.0 becomes (3, 2, 0). 3.2.4 becomes (3, 2, 4). Python compares tuples from the left. The first two places are equal, and 0 < 4, so the update test is true for donate-form. The appended text is UPDATE to 3.2.4, using the fixed string already stored in the tuple. The script does not fetch an advisory page.
The same helper would treat 3.10 as (3, 10) and 3.9 as (3, 9). Those tuples compare as ten greater than nine. Character order on the raw strings goes the other way, because the character 1 precedes the character 9. This file contains neither 3.10 nor 3.9. The helper is also not packaging.version, and a suffix such as a pre-release tag is not present to be parsed. map(int, ...) would raise on a non-numeric piece. No tuple here has such a piece.
if fixed and v(ver) < v(fixed) skips the comparison when fixed is None, because None is false. event-calendar, photo-gallery, and newsletter store None in that field, so they cannot receive an UPDATE note from this test. An installed tuple equal to its fixed tuple would also fail the strict <. donate-form is still 3.2.0 in the file. The later update to 3.2.4 is prose and does not edit this tuple.
Lesson table; scroll horizontally to read all columns →
| Pair | Comparison this helper would make | Present in the four tuples? |
|---|---|---|
(3, 2, 0) and (3, 2, 4) |
Installed is less | Yes, donate-form |
(3, 10) and (3, 9) |
Ten is greater than nine | No |
Raw strings 3.10 and 3.9 |
Not what v does |
No |
6.2 Worked example
Lesson table; scroll horizontally to read all columns →
| Claim | Tuple fact | Decision |
|---|---|---|
donate-form 3.2.0 is behind 3.2.4 |
(3, 2, 0) < (3, 2, 4) |
Keep |
| The other three rows have no fixed version | fixed is None |
Keep |
"3.10 would sort before 3.9 inside this helper." |
Integer tuples do the opposite, and neither value is stored | Refuse |
| "The script already shows 3.2.4 installed." | The stored version is still 3.2.0 |
Refuse |
Synthetic case. No advisory identifier is stored beside the fixed version.
Errors and limits
Do not treat a version this list never stored as a result of the run.
Apply
- EX052 — Two comparisons. A classmate says donate-form is flagged because the text
3.2.0comes before3.2.4in the alphabet, and that the same helper would treat3.10as older than3.9. What doesvcompare, and which of those strings are in the file?Show marking criteria
Rubric: 3 = integer tuples;(3, 2, 0) < (3, 2, 4);(3, 10)is greater than(3, 9);3.10and3.9are absent; the installed donate-form string stays3.2.0;; 2 = the helper uses integers and the stored version stays;; 1 = one comparison;; 0 = none.