From 001a028311f6e92ab577e3f6f23d1f37cd12544d Mon Sep 17 00:00:00 2001 From: sg3-141-592 <5122866+sg3-141-592@users.noreply.github.com> Date: Wed, 7 Jun 2023 19:34:37 +0000 Subject: [PATCH] Updating in response to review --- src/urllib3/request.py | 11 ++++++----- test/test_request.py | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/urllib3/request.py b/src/urllib3/request.py index a84c0e465c..f4cd984f0b 100644 --- a/src/urllib3/request.py +++ b/src/urllib3/request.py @@ -1,7 +1,6 @@ from __future__ import absolute_import import sys -import warnings from .filepost import encode_multipart_formdata from .packages import six @@ -176,16 +175,18 @@ def request_encode_body( if not six.PY2: - class RequestModule(object): + class RequestModule(sys.modules[__name__].__class__): def __call__(self, *args, **kwargs): """ If user tries to call this module directly urllib3 v2.x style raise an error to the user + suggesting they may need urllib3 v2 """ - warnings.warn( - "urllib3.requests() method is not supported in this release\n" + raise TypeError( + "TypeError: 'module' object is not callable\n" + "urllib3.requests() method is not supported in this release, " "upgrade to urllib3 v2 to use it" ) RequestMethods = RequestMethods - sys.modules[__name__] = RequestModule() + sys.modules[__name__].__class__ = RequestModule diff --git a/test/test_request.py b/test/test_request.py index 440d0fd088..f9834ba56d 100644 --- a/test/test_request.py +++ b/test/test_request.py @@ -12,5 +12,5 @@ class TestRequestImport(object): def test_request_import_warning(self): """Ensure an appropriate error is raised to the user if they try and run urllib3.request()""" - with pytest.warns(UserWarning): + with pytest.raises(TypeError): urllib3.request(1, a=2)