You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 maintained
0 commit comments