Diff¶
lcp.diff ¶
Diff module for comparing two LCP documents and detecting deprecated symbols.
SymbolDiff
dataclass
¶
Description of a single symbol difference between two LCP documents.
Source code in src/lcp/diff.py
DiffResult
dataclass
¶
Result of comparing two LCP documents.
Attributes:
| Name | Type | Description |
|---|---|---|
old_version |
str
|
Version string of the old library. |
new_version |
str
|
Version string of the new library. |
library_name |
str
|
Name of the library. |
removed |
list[SymbolDiff]
|
Symbols present in old but absent in new (potential deprecations). |
added |
list[SymbolDiff]
|
Symbols present in new but absent in old. |
deprecated |
dict[str, Deprecation]
|
Deprecation entries for removed symbols, keyed by symbol ID. |
Source code in src/lcp/diff.py
to_dict ¶
Convert to a JSON-serializable dictionary.
Source code in src/lcp/diff.py
diff_documents ¶
Compare two LCP documents and detect differences.
Symbols present in old but missing from new are treated as removed
(deprecated). For each removed symbol a Deprecation entry is
created with deprecated_in set to the new document's version.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
old
|
LCPDocument
|
The earlier LCP document. |
required |
new
|
LCPDocument
|
The later LCP document. |
required |
Returns:
| Type | Description |
|---|---|
DiffResult
|
A DiffResult containing removed and added symbols together with |
DiffResult
|
generated deprecation entries. |
Source code in src/lcp/diff.py
update_document ¶
Return a copy of document with deprecation entries from diff_result merged in.
Existing deprecation entries in the document are preserved. New entries from the diff result are added for symbols that were removed between versions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
document
|
LCPDocument
|
The LCP document to update (typically the new version). |
required |
diff_result
|
DiffResult
|
The result of :func: |
required |
Returns:
| Type | Description |
|---|---|
LCPDocument
|
A new LCPDocument with merged deprecation entries. |
Source code in src/lcp/diff.py
load_lcp_document ¶
Load an LCP document from a JSON file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
File path to an LCP JSON file. |
required |
Returns:
| Type | Description |
|---|---|
LCPDocument
|
A parsed LCPDocument. |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If the file does not exist. |
JSONDecodeError
|
If the file is not valid JSON. |
ValidationError
|
If the JSON does not match the LCP schema. |