Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[9660][twisted/internet/_glibbase] Fix Typeerror in simulate for py3 #1679

Merged
merged 3 commits into from Feb 8, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/twisted/internet/_glibbase.py
Expand Up @@ -354,8 +354,8 @@ def simulate(self):
if self._simtag is not None:
self._source_remove(self._simtag)
self.iterate()
timeout = min(self.timeout(), 0.01)
if timeout is None:
timeout = self.timeout()
if timeout is None or timeout > 0.01:
timeout = 0.01
self._simtag = self._timeout_add(
int(timeout * 1000),
Expand Down
33 changes: 33 additions & 0 deletions src/twisted/internet/test/test_glibbase.py
Expand Up @@ -65,3 +65,36 @@ def test_ensureFailsWhenImported(self):
)
self.assertEqual(modules, {"m2": module})
self.assertEqual(e.args, ("A message.",))


try:
from twisted.internet import gireactor as _gireactor
except ImportError:
gireactor = None
else:
gireactor = _gireactor

missingGlibReactor = None
if gireactor is None:
missingGlibReactor = "gi reactor not available"


class GlibReactorBaseTests(TestCase):
"""
Tests for the private C{twisted.internet._glibbase.GlibReactorBase}
done via the public C{twisted.internet.gireactor.PortableGIReactor}
"""

skip = missingGlibReactor

def test_simulate(self):
"""
C{simulate} can be called without raising any errors when there are
no delayed calls for the reactor and hence there is no defined sleep
period.
"""
sut = gireactor.PortableGIReactor(usegtk=False)
# Double check that reactor has no sleep period.
self.assertIs(None, sut.timeout())

sut.simulate()
1 change: 1 addition & 0 deletions src/twisted/newsfragments/9660.bugfix
@@ -0,0 +1 @@
twisted.internet._glibbase.PortableGlibReactorBase.simulate no longer raises TypeError when there are no delayed called. This was a regression introduced with the migration to Python3 in which the builtin `min` function no longer accepts `None` as an argument.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The relevant public names are twisted.internet.gireactor.PortableGIReactor.simulate and twisted.internet.gtk2reactor.PortableGtkReactor.simulate; in general we should avoid news fragments that mention private names (those which have a single underscore directly following a dot)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so....should I change something or you guys gonna figure this one out?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can go ahead and merge this as-is, my comment was more for @adiroiban than you :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Nothing wrong with fixing up the changelog later.)

adiroiban marked this conversation as resolved.
Show resolved Hide resolved