11import time
22from collections import defaultdict , deque
33from datetime import datetime
4- from typing import Optional
54
65import pygit2
76from intervaltree import IntervalTree
1615class GitAttributionTracker :
1716 """Tracks attribution information for code symbols based on git history."""
1817
19- def __init__ (self , codebase : Codebase , ai_authors : Optional [ list [str ]] = None ):
18+ def __init__ (self , codebase : Codebase , ai_authors : list [str ] | None = None ):
2019 """Initialize the attribution tracker.
2120
2221 Args:
@@ -43,7 +42,7 @@ def __init__(self, codebase: Codebase, ai_authors: Optional[list[str]] = None):
4342
4443 self ._commits : deque [Commit ]
4544
46- def build_history (self , max_commits : Optional [ int ] = None ) -> None :
45+ def build_history (self , max_commits : int | None = None ) -> None :
4746 """Build the git history for the codebase.
4847
4948 Args:
@@ -206,7 +205,7 @@ def map_symbols_to_history(self, force=False) -> None:
206205 start_time = time .time ()
207206
208207 print ("Stashing any working directory changes..." )
209- stash_msg = f"Codegen Attribution Stash @ { datetime .now ().timestamp ()} "
208+ stash_msg = f"Codegen Attribution Stash @ { datetime .now ().timestamp ()} " # noqa: DTZ005
210209 stash_id = None
211210 try :
212211 stash_id = self .repo .stash (self .repo .default_signature , stash_msg , include_untracked = True )
@@ -325,7 +324,7 @@ def get_symbol_history(self, symbol: Symbol) -> list[dict]:
325324 symbol_id = f"{ symbol .filepath } :{ symbol .name } "
326325 return self ._symbol_history .get (symbol_id , [])
327326
328- def get_symbol_last_editor (self , symbol : Symbol ) -> Optional [ str ] :
327+ def get_symbol_last_editor (self , symbol : Symbol ) -> str | None :
329328 """Get the last person who edited a symbol.
330329
331330 Args:
@@ -423,12 +422,12 @@ def get_ai_contribution_timeline(self) -> list[tuple[datetime, int]]:
423422 if any (name in author for name in self .ai_authors ):
424423 for commit in commits :
425424 # Convert timestamp to year-month
426- dt = datetime .fromtimestamp (commit ["timestamp" ])
425+ dt = datetime .fromtimestamp (commit ["timestamp" ]) # noqa: DTZ006
427426 month_key = f"{ dt .year } -{ dt .month :02d} "
428427 monthly_counts [month_key ] += 1
429428
430429 # Sort by date
431430 timeline = sorted (monthly_counts .items ())
432431
433432 # Convert to datetime objects
434- return [(datetime .strptime (month , "%Y-%m" ), count ) for month , count in timeline ]
433+ return [(datetime .strptime (month , "%Y-%m" ), count ) for month , count in timeline ] # noqa: DTZ007
0 commit comments