Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
pawamoy committed Nov 24, 2024
1 parent c16c09d commit a209e13
Showing 1 changed file with 86 additions and 7 deletions.
93 changes: 86 additions & 7 deletions src/_griffe/diff.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# This module exports "breaking changes" related utilities.
# The logic here is to iterate on objects and their members recursively,
# to yield found breaking changes.
# This module exports utilities to compute the differences between two versions of an API.
# The logic here is to iterate on objects and their members recursively.
#
# The breakage class definitions might sound a bit verbose,
# but declaring them this way helps with (de)serialization,
Expand All @@ -9,8 +8,9 @@
from __future__ import annotations

import contextlib
from dataclasses import dataclass
from pathlib import Path
from typing import TYPE_CHECKING, Any
from typing import TYPE_CHECKING, Any, ClassVar, Literal

from colorama import Fore, Style

Expand Down Expand Up @@ -576,9 +576,6 @@ def _returns_are_compatible(old_function: Function, new_function: Function) -> b
return True


_sentinel = object()


def find_breaking_changes(
old_obj: Object | Alias,
new_obj: Object | Alias,
Expand All @@ -603,3 +600,85 @@ def find_breaking_changes(
... print(breakage.explain(style=style), file=sys.stderr)
"""
yield from _member_incompatibilities(old_obj, new_obj)


unset = object()


ChangeKind = Literal[
"added object",
"added parameter",
"added base class",
"removed object",
"removed parameter",
"removed base class",
"moved parameter",
"changed object kind",
"changed attribute type",
"changed attribute value",
"changed return type",
"changed parameter type",
"changed parameter default",
"changed parameter kind",
"deprecated object",
"deprecated parameter",
"deprecated parameter type",
"deprecated parameter default",
"deprecated parameter kind",
"deprecated parameter value",
]


@dataclass(kw_only=True)
class AddedObject:
kind: ClassVar[ChangeKind] = "added object"
obj: Object | Alias


@dataclass(kw_only=True)
class AddedParameter:
kind: ClassVar[ChangeKind] = "added parameter"


@dataclass(kw_only=True)
class RemovedObject: ...


@dataclass(kw_only=True)
class RemovedParameter: ...


@dataclass(kw_only=True)
class MovedObject: ...


@dataclass(kw_only=True)
class MovedParameter: ...


@dataclass(kw_only=True)
class ChangedObjectKind: ...


@dataclass(kw_only=True)
class ChangedAttributeValue: ... # added, removed, moved, changed in ordered/unordered sequences/mappings?


@dataclass(kw_only=True)
class ChangedAttributeType: ...


@dataclass(kw_only=True)
class ChangedReturnType: ...


@dataclass(kw_only=True)
class ChangedParameterType: ...


@dataclass(kw_only=True)
class ChangedParameterDefault: ...


@dataclass(kw_only=True)
class ChangedParameterKind: ...

0 comments on commit a209e13

Please sign in to comment.