@@ -114,11 +114,10 @@ class HelperClass:
114
114
def helper_method(self):
115
115
return self.name
116
116
117
-
118
117
class MainClass:
119
118
120
119
def main_method(self):
121
- self.name = HelperClass.NestedClass(" test" ).nested_method()
120
+ self.name = HelperClass.NestedClass(' test' ).nested_method()
122
121
return HelperClass(self.name).helper_method()
123
122
```
124
123
"""
@@ -181,22 +180,17 @@ class Graph:
181
180
182
181
def topologicalSortUtil(self, v, visited, stack):
183
182
visited[v] = True
184
-
185
183
for i in self.graph[v]:
186
184
if visited[i] == False:
187
185
self.topologicalSortUtil(i, visited, stack)
188
-
189
186
stack.insert(0, v)
190
187
191
188
def topologicalSort(self):
192
189
visited = [False] * self.V
193
190
stack = []
194
-
195
191
for i in range(self.V):
196
192
if visited[i] == False:
197
193
self.topologicalSortUtil(i, visited, stack)
198
-
199
- # Print contents of stack
200
194
return stack
201
195
```
202
196
"""
@@ -614,58 +608,37 @@ class _PersistentCache(Generic[_P, _R, _CacheBackendT]):
614
608
```python:{ file_path .relative_to (opt .args .project_root )}
615
609
class AbstractCacheBackend(CacheBackend, Protocol[_KEY_T, _STORE_T]):
616
610
617
- def get_cache_or_call(
618
- self,
619
- *,
620
- func: Callable[_P, Any],
621
- args: tuple[Any, ...],
622
- kwargs: dict[str, Any],
623
- lifespan: datetime.timedelta,
624
- ) -> Any: # noqa: ANN401
625
- if os.environ.get("NO_CACHE"):
611
+ def get_cache_or_call(self, *, func: Callable[_P, Any], args: tuple[Any, ...], kwargs: dict[str, Any], lifespan: datetime.timedelta) -> Any:
612
+ if os.environ.get('NO_CACHE'):
626
613
return func(*args, **kwargs)
627
-
628
614
try:
629
615
key = self.hash_key(func=func, args=args, kwargs=kwargs)
630
- except: # noqa: E722
631
- # If we can't create a cache key, we should just call the function.
632
- logging.warning("Failed to hash cache key for function: %s", func)
616
+ except:
617
+ logging.warning('Failed to hash cache key for function: %s', func)
633
618
return func(*args, **kwargs)
634
619
result_pair = self.get(key=key)
635
-
636
620
if result_pair is not None:
637
621
cached_time, result = result_pair
638
- if not os.environ.get("RE_CACHE") and (
639
- datetime.datetime.now() < (cached_time + lifespan) # noqa: DTZ005
640
- ):
622
+ if not os.environ.get('RE_CACHE') and datetime.datetime.now() < cached_time + lifespan:
641
623
try:
642
624
return self.decode(data=result)
643
625
except CacheBackendDecodeError as e:
644
- logging.warning("Failed to decode cache data: %s", e)
645
- # If decoding fails we will treat this as a cache miss.
646
- # This might happens if underlying class definition of the data changes.
626
+ logging.warning('Failed to decode cache data: %s', e)
647
627
self.delete(key=key)
648
628
result = func(*args, **kwargs)
649
629
try:
650
630
self.put(key=key, data=self.encode(data=result))
651
631
except CacheBackendEncodeError as e:
652
- logging.warning("Failed to encode cache data: %s", e)
653
- # If encoding fails, we should still return the result.
632
+ logging.warning('Failed to encode cache data: %s', e)
654
633
return result
655
634
656
-
657
635
class _PersistentCache(Generic[_P, _R, _CacheBackendT]):
658
636
659
637
def __call__(self, *args: _P.args, **kwargs: _P.kwargs) -> _R:
660
- if " NO_CACHE" in os.environ:
638
+ if ' NO_CACHE' in os.environ:
661
639
return self.__wrapped__(*args, **kwargs)
662
640
os.makedirs(DEFAULT_CACHE_LOCATION, exist_ok=True)
663
- return self.__backend__.get_cache_or_call(
664
- func=self.__wrapped__,
665
- args=args,
666
- kwargs=kwargs,
667
- lifespan=self.__duration__,
668
- )
641
+ return self.__backend__.get_cache_or_call(func=self.__wrapped__, args=args, kwargs=kwargs, lifespan=self.__duration__)
669
642
```
670
643
"""
671
644
assert read_write_context .strip () == expected_read_write_context .strip ()
@@ -749,10 +722,12 @@ def __repr__(self):
749
722
expected_hashing_context = f"""
750
723
```python:{ file_path .relative_to (opt .args .project_root )}
751
724
class MyClass:
725
+
752
726
def target_method(self):
753
727
y = HelperClass().helper_method()
754
728
755
729
class HelperClass:
730
+
756
731
def helper_method(self):
757
732
return self.x
758
733
```
@@ -843,10 +818,12 @@ def __repr__(self):
843
818
expected_hashing_context = f"""
844
819
```python:{ file_path .relative_to (opt .args .project_root )}
845
820
class MyClass:
821
+
846
822
def target_method(self):
847
823
y = HelperClass().helper_method()
848
824
849
825
class HelperClass:
826
+
850
827
def helper_method(self):
851
828
return self.x
852
829
```
@@ -927,10 +904,12 @@ def helper_method(self):
927
904
expected_hashing_context = f"""
928
905
```python:{ file_path .relative_to (opt .args .project_root )}
929
906
class MyClass:
907
+
930
908
def target_method(self):
931
909
y = HelperClass().helper_method()
932
910
933
911
class HelperClass:
912
+
934
913
def helper_method(self):
935
914
return self.x
936
915
```
@@ -1116,22 +1095,17 @@ class DataProcessor:
1116
1095
def process_data(self, raw_data: str) -> str:
1117
1096
return raw_data.upper()
1118
1097
1119
- def add_prefix(self, data: str, prefix: str = " PREFIX_" ) -> str:
1098
+ def add_prefix(self, data: str, prefix: str=' PREFIX_' ) -> str:
1120
1099
return prefix + data
1121
1100
```
1122
1101
```python:{ path_to_file .relative_to (project_root )}
1123
1102
def fetch_and_process_data():
1124
- # Use the global variable for the request
1125
1103
response = requests.get(API_URL)
1126
1104
response.raise_for_status()
1127
-
1128
1105
raw_data = response.text
1129
-
1130
- # Use code from another file (utils.py)
1131
1106
processor = DataProcessor()
1132
1107
processed = processor.process_data(raw_data)
1133
1108
processed = processor.add_prefix(processed)
1134
-
1135
1109
return processed
1136
1110
```
1137
1111
"""
@@ -1225,16 +1199,11 @@ def transform_data(self, data: str) -> str:
1225
1199
```
1226
1200
```python:{ path_to_file .relative_to (project_root )}
1227
1201
def fetch_and_transform_data():
1228
- # Use the global variable for the request
1229
1202
response = requests.get(API_URL)
1230
-
1231
1203
raw_data = response.text
1232
-
1233
- # Use code from another file (utils.py)
1234
1204
processor = DataProcessor()
1235
1205
processed = processor.process_data(raw_data)
1236
1206
transformed = processor.transform_data(processed)
1237
-
1238
1207
return transformed
1239
1208
```
1240
1209
"""
@@ -1450,9 +1419,8 @@ def transform_data_all_same_file(self, data):
1450
1419
new_data = update_data(data)
1451
1420
return self.transform_using_own_method(new_data)
1452
1421
1453
-
1454
1422
def update_data(data):
1455
- return data + " updated"
1423
+ return data + ' updated'
1456
1424
```
1457
1425
"""
1458
1426
@@ -1591,6 +1559,7 @@ def outside_method():
1591
1559
expected_hashing_context = f"""
1592
1560
```python:{ file_path .relative_to (opt .args .project_root )}
1593
1561
class MyClass:
1562
+
1594
1563
def target_method(self):
1595
1564
return self.x + self.y
1596
1565
```
@@ -1640,16 +1609,11 @@ def transform_data(self, data: str) -> str:
1640
1609
expected_hashing_context = """
1641
1610
```python:main.py
1642
1611
def fetch_and_transform_data():
1643
- # Use the global variable for the request
1644
1612
response = requests.get(API_URL)
1645
-
1646
1613
raw_data = response.text
1647
-
1648
- # Use code from another file (utils.py)
1649
1614
processor = DataProcessor()
1650
1615
processed = processor.process_data(raw_data)
1651
1616
transformed = processor.transform_data(processed)
1652
-
1653
1617
return transformed
1654
1618
```
1655
1619
```python:import_test.py
@@ -1915,9 +1879,9 @@ def subtract(self, a, b):
1915
1879
return a - b
1916
1880
1917
1881
def calculate(self, operation, x, y):
1918
- if operation == " add" :
1882
+ if operation == ' add' :
1919
1883
return self.add(x, y)
1920
- elif operation == " subtract" :
1884
+ elif operation == ' subtract' :
1921
1885
return self.subtract(x, y)
1922
1886
else:
1923
1887
return None
0 commit comments