Permalink
Browse files

AsyncHTTPClient: remove legacy magic around max_clients arg.

Fix a bug in which configured kwargs would be applied to a non-configured
class.
  • Loading branch information...
1 parent 9a04c2b commit 13a62380b0e78c3f410c8628c00f850d7ead2d39 @bdarnell bdarnell committed Oct 1, 2012
Showing with 8 additions and 18 deletions.
  1. +4 −13 tornado/httpclient.py
  2. +0 −5 tornado/test/simple_httpclient_test.py
  3. +4 −0 website/sphinx/releases/next.rst
View
@@ -124,39 +124,30 @@ def handle_request(response):
_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"
if not hasattr(cls, '_async_client_dict'):
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
@@ -316,15 +316,10 @@ def tearDown(self):
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)
@@ -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.

0 comments on commit 13a6238

Please sign in to comment.