From: Ben Darnell Date: Mon, 1 Oct 2012 02:10:16 +0000 (-0700) Subject: AsyncHTTPClient: remove legacy magic around max_clients arg. X-Git-Tag: v3.0.0~252 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=13a62380b0e78c3f410c8628c00f850d7ead2d39;p=thirdparty%2Ftornado.git AsyncHTTPClient: remove legacy magic around max_clients arg. Fix a bug in which configured kwargs would be applied to a non-configured class. --- diff --git a/tornado/httpclient.py b/tornado/httpclient.py index a381f9bde..bf17fdebb 100644 --- a/tornado/httpclient.py +++ b/tornado/httpclient.py @@ -124,8 +124,6 @@ class AsyncHTTPClient(object): _impl_class = None _impl_kwargs = None - _DEFAULT_MAX_CLIENTS = 10 - @classmethod def _async_clients(cls): assert cls is not AsyncHTTPClient, "should only be called on subclasses" @@ -133,30 +131,23 @@ class AsyncHTTPClient(object): cls._async_client_dict = weakref.WeakKeyDictionary() return cls._async_client_dict - def __new__(cls, io_loop=None, max_clients=None, force_instance=False, - **kwargs): + def __new__(cls, io_loop=None, force_instance=False, **kwargs): io_loop = io_loop or IOLoop.instance() + args = {} if cls is AsyncHTTPClient: if cls._impl_class is None: from tornado.simple_httpclient import SimpleAsyncHTTPClient AsyncHTTPClient._impl_class = SimpleAsyncHTTPClient impl = AsyncHTTPClient._impl_class + if cls._impl_kwargs: + args.update(cls._impl_kwargs) else: impl = cls if io_loop in impl._async_clients() and not force_instance: return impl._async_clients()[io_loop] else: instance = super(AsyncHTTPClient, cls).__new__(impl) - args = {} - if cls._impl_kwargs: - args.update(cls._impl_kwargs) args.update(kwargs) - if max_clients is not None: - # max_clients is special because it may be passed - # positionally instead of by keyword - args["max_clients"] = max_clients - elif "max_clients" not in args: - args["max_clients"] = AsyncHTTPClient._DEFAULT_MAX_CLIENTS instance.initialize(io_loop, **args) if not force_instance: impl._async_clients()[io_loop] = instance diff --git a/tornado/test/simple_httpclient_test.py b/tornado/test/simple_httpclient_test.py index dbd836a3c..1d6859c3d 100644 --- a/tornado/test/simple_httpclient_test.py +++ b/tornado/test/simple_httpclient_test.py @@ -316,15 +316,10 @@ class CreateAsyncHTTPClientTestCase(AsyncTestCase): super(CreateAsyncHTTPClientTestCase, self).tearDown() def test_max_clients(self): - # The max_clients argument is tricky because it was originally - # allowed to be passed positionally; newer arguments are keyword-only. AsyncHTTPClient.configure(SimpleAsyncHTTPClient) with closing(AsyncHTTPClient( self.io_loop, force_instance=True)) as client: self.assertEqual(client.max_clients, 10) - with closing(AsyncHTTPClient( - self.io_loop, 11, force_instance=True)) as client: - self.assertEqual(client.max_clients, 11) with closing(AsyncHTTPClient( self.io_loop, max_clients=11, force_instance=True)) as client: self.assertEqual(client.max_clients, 11) diff --git a/website/sphinx/releases/next.rst b/website/sphinx/releases/next.rst index 87f721bf5..4ff63115f 100644 --- a/website/sphinx/releases/next.rst +++ b/website/sphinx/releases/next.rst @@ -100,3 +100,7 @@ In progress independent option sets, such as for subcommands. * `tornado.options.options` is no longer a subclass of `dict`; attribute-style access is now required. +* The ``max_clients`` argument to `AsyncHTTPClient` is now a keyword-only + argument. +* Keyword arguments to `AsyncHTTPClient.configure` are no longer used + when instantiating an implementation subclass directly.