Skip to content

Commit

Permalink
Use @functools.lru_cache on Project factory constructor
Browse files Browse the repository at this point in the history
Co-authored-by: Jason R. Coombs <[email protected]>
  • Loading branch information
bswck and jaraco authored Mar 26, 2024
1 parent fae562e commit ca80812
Showing 1 changed file with 2 additions and 9 deletions.
11 changes: 2 additions & 9 deletions jaraco/develop/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,17 +120,10 @@ class Project(str):

pattern = re.compile(r'(?P<name>\S+)\s*(?P<rest>.*)$')
tags: list[str] = []
cache: dict[str, Project] = {}

@functools.lru_cache
def __new__(cls, value, **kwargs):
# Down-cast to a string early.
value = sys.intern(str(value))
try:
return cls.cache[value]
except KeyError:
new = super().__new__(cls, value)
cls.cache[new] = new
return new
return super().__new__(cls, value)

def __init__(self, value, **kwargs):
vars(self).update({'topics': [], **kwargs})
Expand Down

0 comments on commit ca80812

Please sign in to comment.