YamlDifferently

class differently.YamlDifferently(a: Optional[Any], b: Optional[Any], color: bool = True)

Visualises the differences between two objects as YAML.

Use the string representation or inherited ListDifferently.render() to render.

Parameters
  • a – First object

  • b – Second object

  • color – Include or exclude colour formatting (default is True)

Example

from differently import YamlDifferently
from typing import List, TypedDict

class PersonDict(TypedDict):
    name: str
    movies: List[str]

a: PersonDict = {
    "name": "Danny Jam",
    "movies": [
        "Oh, What a Lovely Implosion!",
        "Touch It and Die",
        "Mice! Mice! Mice!",
    ],
}

b: PersonDict = {
    "name": "Sandy Jelly",
    "movies": [
        "Oh, What a Lovely Explosion!",
        "Mice! Mice! Mice!",
    ],
}

diff = YamlDifferently(a, b, color=False)
print(diff)
movies:                         =  movies:
- Oh, What a Lovely Implosion!  ~  - Oh, What a Lovely Explosion!
- Touch It and Die              x
- Mice! Mice! Mice!             =  - Mice! Mice! Mice!
name: Danny Jam                 ~  name: Sandy Jelly
static load(i: Union[pathlib.Path, str]) Any

If i is a Path then deserialises the file at that location as YAML.

If i is a str then deserialises i as YAML.

Raises DeserializationError if deserialisation fails.