<a id="ch-06"></a>

## Chapter 6 — A version tuple is not a decimal string

<!-- open-cyber-academy:lesson-figures:start ch-06 -->
### Lesson map

Lesson 06. Map, example, EX052.

```mermaid
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

```text
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
```
<!-- open-cyber-academy:lesson-figures:end ch-06 -->

### Learning outcomes

After this chapter, you should be able to:

1. Explain `v` as a split into integers.
2. Show why `(3, 2, 0)` is less than `(3, 2, 4)`.
3. 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.

| 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

| 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.0` comes before `3.2.4` in the alphabet, and that the same helper would treat `3.10` as older than `3.9`. What does `v` compare, and which of those strings are in the file? *Rubric:* 3 = integer tuples; `(3, 2, 0) < (3, 2, 4)`; `(3, 10)` is greater than `(3, 9)`; `3.10` and `3.9` are absent; the installed donate-form string stays `3.2.0`;; 2 = the helper uses integers and the stored version stays;; 1 = one comparison;; 0 = none.

<!-- open-cyber-academy:chapter-navigation:start ch-06 -->
### Continue studying — lesson 06 (chapter 06 of 20)

[← Chapter 05](#ch-05) · [Course chapter index](../SUBJECTS.md) · [Chapter 07 →](#ch-07)

Continue to the next authored lesson.
<!-- open-cyber-academy:chapter-navigation:end -->

## Worked answers

<a id="answer-ex052"></a>
**EX052.** `v` compares integer tuples. `(3, 2, 0) < (3, 2, 4)`, so donate-form is flagged. `(3, 10)` is greater than `(3, 9)`. Neither `3.10` nor `3.9` is in the file. The stored version remains `3.2.0`.
