Skip to content

Commit

Permalink
Shuffle the pieces around to avoid the staticmethod mypy error
Browse files Browse the repository at this point in the history
  • Loading branch information
exarkun committed Sep 27, 2022
1 parent a017e45 commit 00d2b7a
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/twisted/internet/test/reactormixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
if TYPE_CHECKING:
# Only bring in this name to support the type annotation below. We don't
# really want to import a reactor module this early at runtime.
from twisted.internet.asyncioreactor import AsyncioSelectorReactor
from twisted.internet import asyncioreactor

# Access private APIs.
try:
Expand Down Expand Up @@ -158,7 +158,7 @@ class ReactorBuilder:
]
)

_reactors.append("twisted.internet.test.reactormixins.AsyncioSelectReactor")
_reactors.append("twisted.internet.test.reactormixins.AsyncioSelectorReactor")

if platform.isMacOSX():
_reactors.append("twisted.internet.cfreactor.CFReactor")
Expand Down Expand Up @@ -373,8 +373,7 @@ class testcase(cls, SynchronousTestCase): # type: ignore[valid-type,misc]
return classes


@staticmethod
def AsyncioSelectReactor() -> "AsyncioSelectorReactor":
def asyncioSelectorReactor(self: object) -> "asyncioreactor.AsyncioSelectorReactor":
"""
Make a new asyncio reactor associated with a new event loop.
Expand All @@ -384,15 +383,19 @@ def AsyncioSelectReactor() -> "AsyncioSelectorReactor":
with other asyncio-based libraries and applications (though maybe it
shouldn't).
@note: This function's name deviates from the coding standard because the
name of the generated test cases is derived from it. The given name
reflects the name of the reactor the generated tests will cover.
@param self: The L{ReactorBuilder} subclass this is being called on. We
don't use this parameter but we get called with it anyway.
"""
from asyncio import new_event_loop, set_event_loop

from twisted.internet.asyncioreactor import AsyncioSelectorReactor
from twisted.internet import asyncioreactor

loop = new_event_loop()
set_event_loop(loop)

return AsyncioSelectorReactor(loop)
return asyncioreactor.AsyncioSelectorReactor(loop)


# Give it an alias that makes the names of the generated test classes fit the
# pattern.
AsyncioSelectorReactor = asyncioSelectorReactor

0 comments on commit 00d2b7a

Please sign in to comment.