Skip to content

Commit ad28ab4

Browse files
alexmalyshevfacebook-github-bot
authored andcommitted
Fix Pyre-Strict warning in test_jit_async_generators
Summary: ## Instructions about RACER Diffs: **This feature is still in BETA and we are continuously improving it. Your constructive feedback would help improving RACER and highly appreciated.** This diff was pre-created by Racer AI agent for your convenience on top of T230049091. How-to-code instruction is provided by oncall [Sky Jazayeri](https://www.internalfb.com/profile/view/1047504621). For questions or suggestions please post in [RACER Autonomous Codebase Management](https://fb.workplace.com/groups/742040101615185) group. This diff fixes a 'Pyre Strict' issue identified by Quality Insight from [Monetization codehub](https://fburl.com/quality/wmkbc0si). - If you are happy with the changes, commandeer it if minor edits are needed. (**we encourage commandeer to get the diff credit**) - If you are not happy with the changes, please comment on the diff with clear actions and send it back to the author. Racer will pick it up and re-generate. - If you really feel the Racer is not helping with this change (alas, some complex changes are hard for AI) feel free to abandon this diff. ## Summary: This diff converts the test_jit_async_generators.py file from 'pyre-unsafe' to 'pyre-strict' by adding appropriate type annotations to all functions, method parameters, and return values. It also adds proper type hints for variables and resolves unawaited awaitable warnings with appropriate pyre-ignore annotations. --- > Generated by [RACER](https://www.internalfb.com/wiki/RACER_(Risk-Aware_Code_Editing_and_Refactoring)/), powered by [Confucius](https://www.internalfb.com/wiki/Confucius/Analect/Shared_Analects/Confucius_Code_Assist_(CCA)/) [Session](https://www.internalfb.com/confucius?session_id=b0e88209-5ad0-11f0-ab16-460e1a24fa6e&tab=Chat), [Trace](https://www.internalfb.com/confucius?session_id=b0e88209-5ad0-11f0-ab16-460e1a24fa6e&tab=Trace) Reviewed By: yoney Differential Revision: D77845203 fbshipit-source-id: 6af025b89651a1da9664df2b06c24e2bebe79977
1 parent 360c668 commit ad28ab4

1 file changed

Lines changed: 21 additions & 18 deletions

File tree

PythonLib/test_cinderx/test_jit_async_generators.py

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
# Copyright (c) Meta Platforms, Inc. and affiliates.
2-
# pyre-unsafe
2+
# pyre-strict
33

44
import asyncio
55
import dis
66
import sys
77
import unittest
8+
from typing import Any, AsyncGenerator, Awaitable, Iterator, List
89

910
import cinderx
1011

@@ -13,37 +14,39 @@
1314
import cinderx.test_support as cinder_support
1415

1516

16-
AT_LEAST_312 = sys.version_info[:2] >= (3, 12)
17+
AT_LEAST_312: bool = sys.version_info[:2] >= (3, 12)
1718

1819

1920
@unittest.skipIf(
2021
AT_LEAST_312, "T194022335: Async generators not supported in 3.12 JIT yet"
2122
)
2223
class AsyncGeneratorsTest(unittest.TestCase):
23-
def tearDown(self):
24+
def tearDown(self) -> None:
2425
# This is needed to avoid an "environment changed" error
2526
asyncio.set_event_loop_policy(None)
2627

2728
@cinder_support.failUnlessJITCompiled
28-
async def _f1(self, awaitable):
29+
async def _f1(self, awaitable: Awaitable[Any]) -> AsyncGenerator[int, Any]:
2930
x = yield 1
3031
yield x
3132
await awaitable
3233

33-
def test_basic_coroutine(self):
34+
def test_basic_coroutine(self) -> None:
3435
class DummyAwaitable:
35-
def __await__(self):
36+
def __await__(self) -> Iterator[int]:
3637
return iter([3])
3738

3839
async_gen = self._f1(DummyAwaitable())
3940

4041
# Step 1: move through "yield 1"
42+
# pyre-ignore[1001]: Awaitable is used via .send()
4143
async_itt1 = async_gen.asend(None)
4244
with self.assertRaises(StopIteration) as exc:
4345
async_itt1.send(None)
4446
self.assertEqual(exc.exception.value, 1)
4547

4648
# Step 2: send in and receive out 2 via "yield x"
49+
# pyre-ignore[1001]: Awaitable is used via .send()
4750
async_itt2 = async_gen.asend(2)
4851
with self.assertRaises(StopIteration) as exc:
4952
async_itt2.send(None)
@@ -58,20 +61,20 @@ def __await__(self):
5861
async_itt3.send(None)
5962

6063
@cinder_support.failUnlessJITCompiled
61-
async def _f2(self, asyncgen):
62-
res = []
64+
async def _f2(self, asyncgen: AsyncGenerator[int, None]) -> List[int]:
65+
res: List[int] = []
6366
async for x in asyncgen:
6467
res.append(x)
6568
return res
6669

67-
def test_for_iteration(self):
68-
async def asyncgen():
70+
def test_for_iteration(self) -> None:
71+
async def asyncgen() -> AsyncGenerator[int, None]:
6972
yield 1
7073
yield 2
7174

7275
self.assertEqual(asyncio.run(self._f2(asyncgen())), [1, 2])
7376

74-
def _assertExceptionFlowsThroughYieldFrom(self, exc):
77+
def _assertExceptionFlowsThroughYieldFrom(self, exc: Exception) -> None:
7578
tb_prev = None
7679
tb = exc.__traceback__
7780
while tb.tb_next:
@@ -83,8 +86,8 @@ def _assertExceptionFlowsThroughYieldFrom(self, exc):
8386
"YIELD_VALUE" if AT_LEAST_312 else "YIELD_FROM",
8487
)
8588

86-
def test_for_exception(self):
87-
async def asyncgen():
89+
def test_for_exception(self) -> None:
90+
async def asyncgen() -> AsyncGenerator[int, None]:
8891
yield 1
8992
raise ValueError
9093

@@ -97,18 +100,18 @@ async def asyncgen():
97100
self.fail("Expected ValueError to be raised")
98101

99102
@cinder_support.failUnlessJITCompiled
100-
async def _f3(self, asyncgen):
103+
async def _f3(self, asyncgen: AsyncGenerator[int, None]) -> List[int]:
101104
return [x async for x in asyncgen]
102105

103-
def test_comprehension(self):
104-
async def asyncgen():
106+
def test_comprehension(self) -> None:
107+
async def asyncgen() -> AsyncGenerator[int, None]:
105108
yield 1
106109
yield 2
107110

108111
self.assertEqual(asyncio.run(self._f3(asyncgen())), [1, 2])
109112

110-
def test_comprehension_exception(self):
111-
async def asyncgen():
113+
def test_comprehension_exception(self) -> None:
114+
async def asyncgen() -> AsyncGenerator[int, None]:
112115
yield 1
113116
raise ValueError
114117

0 commit comments

Comments
 (0)