Skip to content

Schemas

Schema definitions for diff splitting.

DiffChunk dataclass

Represents a logical chunk of changes.

Source code in src/codemap/git/diff_splitter/schemas.py
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
@dataclass
class DiffChunk:
	"""Represents a logical chunk of changes."""

	files: list[str] = field(default_factory=list)
	content: str = ""
	description: str | None = None
	embedding: list[float] | None = None
	is_move: bool = False  # Indicates if this chunk represents a file move operation
	is_llm_generated: bool = False
	filtered_files: list[str] | None = None

	def __post_init__(self) -> None:
		"""Initialize default values."""
		if self.filtered_files is None:
			self.filtered_files = []

	def __hash__(self) -> int:
		"""
		Make DiffChunk hashable by using the object's id.

		Returns:
		        Hash value based on the object's id

		"""
		return hash(id(self))

	def __eq__(self, other: object) -> bool:
		"""
		Compare DiffChunk objects for equality.

		Args:
		        other: Another object to compare with

		Returns:
		        True if the objects are the same instance, False otherwise

		"""
		if not isinstance(other, DiffChunk):
			return False
		return id(self) == id(other)

__init__

__init__(
	files: list[str] = list(),
	content: str = "",
	description: str | None = None,
	embedding: list[float] | None = None,
	is_move: bool = False,
	is_llm_generated: bool = False,
	filtered_files: list[str] | None = None,
) -> None

files class-attribute instance-attribute

files: list[str] = field(default_factory=list)

content class-attribute instance-attribute

content: str = ''

description class-attribute instance-attribute

description: str | None = None

embedding class-attribute instance-attribute

embedding: list[float] | None = None

is_move class-attribute instance-attribute

is_move: bool = False

is_llm_generated class-attribute instance-attribute

is_llm_generated: bool = False

filtered_files class-attribute instance-attribute

filtered_files: list[str] | None = None

__post_init__

__post_init__() -> None

Initialize default values.

Source code in src/codemap/git/diff_splitter/schemas.py
19
20
21
22
def __post_init__(self) -> None:
	"""Initialize default values."""
	if self.filtered_files is None:
		self.filtered_files = []

__hash__

__hash__() -> int

Make DiffChunk hashable by using the object's id.

Returns:

Type Description
int

Hash value based on the object's id

Source code in src/codemap/git/diff_splitter/schemas.py
24
25
26
27
28
29
30
31
32
def __hash__(self) -> int:
	"""
	Make DiffChunk hashable by using the object's id.

	Returns:
	        Hash value based on the object's id

	"""
	return hash(id(self))

__eq__

__eq__(other: object) -> bool

Compare DiffChunk objects for equality.

Parameters:

Name Type Description Default
other object

Another object to compare with

required

Returns:

Type Description
bool

True if the objects are the same instance, False otherwise

Source code in src/codemap/git/diff_splitter/schemas.py
34
35
36
37
38
39
40
41
42
43
44
45
46
47
def __eq__(self, other: object) -> bool:
	"""
	Compare DiffChunk objects for equality.

	Args:
	        other: Another object to compare with

	Returns:
	        True if the objects are the same instance, False otherwise

	"""
	if not isinstance(other, DiffChunk):
		return False
	return id(self) == id(other)

DiffChunkData dataclass

Dictionary-based representation of a DiffChunk for serialization.

Source code in src/codemap/git/diff_splitter/schemas.py
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
@dataclass
class DiffChunkData:
	"""Dictionary-based representation of a DiffChunk for serialization."""

	files: list[str]
	content: str
	description: str | None = None
	is_llm_generated: bool = False
	filtered_files: list[str] | None = None
	is_move: bool = False  # Indicates if this chunk represents a file move operation

	@classmethod
	def from_chunk(cls, chunk: DiffChunk) -> "DiffChunkData":
		"""Create a DiffChunkData from a DiffChunk."""
		return cls(
			files=chunk.files,
			content=chunk.content,
			description=chunk.description,
			is_llm_generated=chunk.is_llm_generated,
			filtered_files=chunk.filtered_files,
			is_move=getattr(chunk, "is_move", False),
		)

	def to_chunk(self) -> DiffChunk:
		"""Convert DiffChunkData to a DiffChunk."""
		return DiffChunk(
			files=self.files,
			content=self.content,
			description=self.description,
			is_llm_generated=self.is_llm_generated,
			filtered_files=self.filtered_files,
			is_move=self.is_move,
		)

	def to_dict(self) -> dict[str, Any]:
		"""Convert to a dictionary."""
		return {
			"files": self.files,
			"content": self.content,
			"description": self.description,
			"is_llm_generated": self.is_llm_generated,
			"filtered_files": self.filtered_files,
			"is_move": self.is_move,
		}

__init__

__init__(
	files: list[str],
	content: str,
	description: str | None = None,
	is_llm_generated: bool = False,
	filtered_files: list[str] | None = None,
	is_move: bool = False,
) -> None

files instance-attribute

files: list[str]

content instance-attribute

content: str

description class-attribute instance-attribute

description: str | None = None

is_llm_generated class-attribute instance-attribute

is_llm_generated: bool = False

filtered_files class-attribute instance-attribute

filtered_files: list[str] | None = None

is_move class-attribute instance-attribute

is_move: bool = False

from_chunk classmethod

from_chunk(chunk: DiffChunk) -> DiffChunkData

Create a DiffChunkData from a DiffChunk.

Source code in src/codemap/git/diff_splitter/schemas.py
61
62
63
64
65
66
67
68
69
70
71
@classmethod
def from_chunk(cls, chunk: DiffChunk) -> "DiffChunkData":
	"""Create a DiffChunkData from a DiffChunk."""
	return cls(
		files=chunk.files,
		content=chunk.content,
		description=chunk.description,
		is_llm_generated=chunk.is_llm_generated,
		filtered_files=chunk.filtered_files,
		is_move=getattr(chunk, "is_move", False),
	)

to_chunk

to_chunk() -> DiffChunk

Convert DiffChunkData to a DiffChunk.

Source code in src/codemap/git/diff_splitter/schemas.py
73
74
75
76
77
78
79
80
81
82
def to_chunk(self) -> DiffChunk:
	"""Convert DiffChunkData to a DiffChunk."""
	return DiffChunk(
		files=self.files,
		content=self.content,
		description=self.description,
		is_llm_generated=self.is_llm_generated,
		filtered_files=self.filtered_files,
		is_move=self.is_move,
	)

to_dict

to_dict() -> dict[str, Any]

Convert to a dictionary.

Source code in src/codemap/git/diff_splitter/schemas.py
84
85
86
87
88
89
90
91
92
93
def to_dict(self) -> dict[str, Any]:
	"""Convert to a dictionary."""
	return {
		"files": self.files,
		"content": self.content,
		"description": self.description,
		"is_llm_generated": self.is_llm_generated,
		"filtered_files": self.filtered_files,
		"is_move": self.is_move,
	}