Commit da716a7
feat: introduce Source inheritance hierarchy with pure Python polymorphism
This refactor introduces a clean inheritance architecture using proper Python polymorphism:
Architecture:
- Add Source base class in dedicated source.py file (common metadata/extra fields)
- Refactor FileSystemNode to inherit from Source with full backward compatibility
- Create specialized classes: FileSystemFile, FileSystemDirectory, FileSystemSymlink, GitRepository
- render_tree() method belongs to FileSystemNode level (tree-specific, not all sources need it)
Pure Python Polymorphism:
- Each subclass implements its own get_sort_priority() and get_content() methods
- NO type property or enum needed - use isinstance() directly
- FileSystemFile.get_sort_priority() returns 0 (files first)
- FileSystemDirectory.get_content() raises ValueError (directories can't have content)
- FileSystemSymlink.get_content() returns target path (what symlink points to)
- Clean, extensible design following Python best practices
Removed Legacy Type System:
- Completely removed FileSystemNodeType enum
- No more type property - use isinstance() everywhere
- Constructors now use specific classes: FileSystemFile(), FileSystemDirectory(), etc.
- Pure polymorphism without any type checking properties
Code Changes:
- src/gitingest/schemas/source.py: New base Source class
- src/gitingest/schemas/filesystem.py: Refactored with polymorphic methods, Path import in TYPE_CHECKING
- src/gitingest/ingestion.py: Use specific constructors, populate symlink targets
- src/gitingest/output_formatter.py: Use isinstance() instead of enum comparisons
- Remove all FileSystemNodeType imports and usage
- All pre-commit hooks pass (ruff-check, ruff-format, etc.)
Benefits:
- True Python polymorphism where each class knows its own behavior
- No explicit type checking needed - Python dispatches automatically
- More extensible - adding new source types just requires implementing methods
- Cleaner code without enum/string type comparisons
- Full backward compatibility maintained1 parent 38e52cd commit da716a7
File tree
6 files changed
+163
-112
lines changed- .vscode
- src/gitingest
- schemas
6 files changed
+163
-112
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | | - | |
| 8 | + | |
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
| 10 | + | |
| 11 | + | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
| |||
70 | 71 | | |
71 | 72 | | |
72 | 73 | | |
73 | | - | |
| 74 | + | |
74 | 75 | | |
75 | | - | |
76 | 76 | | |
77 | 77 | | |
78 | 78 | | |
| |||
95 | 95 | | |
96 | 96 | | |
97 | 97 | | |
98 | | - | |
| 98 | + | |
99 | 99 | | |
100 | | - | |
101 | 100 | | |
102 | 101 | | |
103 | 102 | | |
| |||
161 | 160 | | |
162 | 161 | | |
163 | 162 | | |
164 | | - | |
| 163 | + | |
165 | 164 | | |
166 | | - | |
167 | 165 | | |
168 | 166 | | |
169 | 167 | | |
| |||
201 | 199 | | |
202 | 200 | | |
203 | 201 | | |
204 | | - | |
| 202 | + | |
205 | 203 | | |
206 | | - | |
207 | 204 | | |
208 | 205 | | |
| 206 | + | |
209 | 207 | | |
210 | 208 | | |
211 | 209 | | |
| |||
258 | 256 | | |
259 | 257 | | |
260 | 258 | | |
261 | | - | |
| 259 | + | |
262 | 260 | | |
263 | | - | |
264 | 261 | | |
265 | 262 | | |
266 | 263 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
12 | | - | |
| 11 | + | |
13 | 12 | | |
14 | 13 | | |
15 | 14 | | |
| |||
42 | 41 | | |
43 | 42 | | |
44 | 43 | | |
45 | | - | |
| 44 | + | |
46 | 45 | | |
47 | 46 | | |
48 | | - | |
| 47 | + | |
49 | 48 | | |
50 | | - | |
| 49 | + | |
51 | 50 | | |
52 | 51 | | |
53 | 52 | | |
| |||
119 | 118 | | |
120 | 119 | | |
121 | 120 | | |
122 | | - | |
| 121 | + | |
123 | 122 | | |
124 | 123 | | |
125 | 124 | | |
| |||
164 | 163 | | |
165 | 164 | | |
166 | 165 | | |
167 | | - | |
| 166 | + | |
168 | 167 | | |
169 | | - | |
170 | | - | |
| 168 | + | |
| 169 | + | |
171 | 170 | | |
172 | 171 | | |
173 | 172 | | |
174 | | - | |
| 173 | + | |
175 | 174 | | |
176 | 175 | | |
177 | 176 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
5 | 12 | | |
| 13 | + | |
6 | 14 | | |
7 | | - | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
0 commit comments