Page MenuHomeSoftware Heritage

swh.model.identifiers: move validation from parsing_persistent_identifier to PersistentId constructor
Closed, MigratedEdits Locked

Description

In swh.model.identifiers, most of the validation checks are done in parse_persistent_identifiers which, after them, build the namedtuple PersistentId. This is safe and sound when building PIDs from strings, but is unsafe when building PersistentId programmatically using it as a named tuple (which is supported by the module, as that class is publicly exposed).

We should move the validation checks from parse_persistent_identifier to the PersistentId constructor.

(The parsing function will inherit validation implicitly.)