Skip to content

Commit

Permalink
Updating in response to review
Browse files Browse the repository at this point in the history
  • Loading branch information
sg3-141-592 committed Jun 7, 2023
1 parent 7d3969e commit 001a028
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
11 changes: 6 additions & 5 deletions 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
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion test/test_request.py
Expand Up @@ -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)

0 comments on commit 001a028

Please sign in to comment.