Merge pull request #44780 from crccw/r2.4

Fix constructor of CommunicationOptions
This commit is contained in:
Ran Chen 2020-11-11 15:03:22 -08:00 committed by GitHub
commit 6eee4b02a8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 2 deletions

View File

@ -81,7 +81,11 @@ class _OptionsExported(object):
"""
def __new__(cls, *args, **kwargs):
return Options.__new__(Options, *args, **kwargs)
# We expose a dummy class so that we can separate internal and public APIs.
# Note that __init__ won't be called on the returned object if it's a
# different class [1].
# [1] https://docs.python.org/3/reference/datamodel.html#object.__new__
return Options(*args, **kwargs)
def __init__(self,
bytes_per_pack=0,

View File

@ -25,8 +25,11 @@ from tensorflow.python.eager import test
class OptionsTest(test.TestCase):
def testCreateOptionsViaExportedAPI(self):
options = collective_util._OptionsExported()
options = collective_util._OptionsExported(bytes_per_pack=1)
self.assertIsInstance(options, collective_util.Options)
self.assertEqual(options.bytes_per_pack, 1)
with self.assertRaises(ValueError):
collective_util._OptionsExported(bytes_per_pack=-1)
def testCreateOptionsViaHints(self):
with self.assertLogs() as cm: