Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/cattrs/gen/_lc.py: 21%
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1"""Line-cache functionality."""
3import linecache
6def generate_unique_filename(cls: type, func_name: str, lines: list[str] = []) -> str:
7 """
8 Create a "filename" suitable for a function being generated.
10 If *lines* are provided, insert them in the first free spot or stop
11 if a duplicate is found.
12 """
13 extra = ""
14 count = 1
16 while True:
17 unique_filename = "<cattrs generated {} {}.{}{}>".format(
18 func_name, cls.__module__, getattr(cls, "__qualname__", cls.__name__), extra
19 )
20 if not lines:
21 return unique_filename
22 cache_line = (len("\n".join(lines)), None, lines, unique_filename)
23 if linecache.cache.setdefault(unique_filename, cache_line) == cache_line:
24 return unique_filename
26 # Looks like this spot is taken. Try again.
27 count += 1
28 extra = f"-{count}"