Repository: praw-dev/praw

Issue:
Timeout not converted to int
**Describe the bug**
<!-- A clear and concise description of what the bug is. -->

No request can be made with the current code. The timeout specified has to be an int, but the config stores it as a string.

**To Reproduce**
Steps to reproduce the behavior:

```python
reddit.request("tesT")
```

**Expected behavior**

Timeout works and the request goes through.

**Code/Logs**

```
In [4]: reddit.subreddit("The_Donald").subscribers                                                                      
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
~/.virtualenvs/praw/venv/lib/python3.7/site-packages/urllib3/util/timeout.py in _validate_timeout(cls, value, name)
    139         try:
--> 140             if value <= 0:
    141                 raise ValueError(

TypeError: '<=' not supported between instances of 'str' and 'int'

During handling of the above exception, another exception occurred:

ValueError                                Traceback (most recent call last)
~/.virtualenvs/praw/venv/lib/python3.7/site-packages/prawcore/requestor.py in request(self, timeout, *args, **kwargs)
     52         try:
---> 53             return self._http.request(*args, timeout=timeout, **kwargs)
     54         except Exception as exc:

~/.virtualenvs/praw/venv/lib/python3.7/site-packages/requests/sessions.py in request(self, method, url, params, data, headers, cookies, files, auth, timeout, allow_redirects, proxies, hooks, stream, verify, cert, json)
    529         send_kwargs.update(settings)
--> 530         resp = self.send(prep, **send_kwargs)
    531 

~/.virtualenvs/praw/venv/lib/python3.7/site-packages/requests/sessions.py in send(self, request, **kwargs)
    642         # Send the request
--> 643         r = adapter.send(request, **kwargs)
    644 

~/.virtualenvs/praw/venv/lib/python3.7/site-packages/requests/adapters.py in send(self, request, stream, timeout, verify, cert, proxies)
    434         else:
--> 435             timeout = TimeoutSauce(connect=timeout, read=timeout)
    436 

~/.virtualenvs/praw/venv/lib/python3.7/site-packages/urllib3/util/timeout.py in __init__(self, total, connect, read)
     95     def __init__(self, total=None, connect=_Default, read=_Default):
---> 96         self._connect = self._validate_timeout(connect, "connect")
     97         self._read = self._validate_timeout(read, "read")

~/.virtualenvs/praw/venv/lib/python3.7/site-packages/urllib3/util/timeout.py in _validate_timeout(cls, value, name)
    149                 "Timeout value %s was %s, but it must be an "
--> 150                 "int, float or None." % (name, value)
    151             )

ValueError: Timeout value connect was 16, but it must be an int, float or None.

During handling of the above exception, another exception occurred:

RequestException                          Traceback (most recent call last)
<ipython-input-4-a5aa025940f1> in <module>
----> 1 reddit.subreddit("The_Donald").subscribers

~/PycharmProjects/praw/praw/models/reddit/base.py in __getattr__(self, attribute)
     31         """Return the value of `attribute`."""
     32         if not attribute.startswith("_") and not self._fetched:
---> 33             self._fetch()
     34             return getattr(self, attribute)
     35         raise AttributeError(

~/PycharmProjects/praw/praw/models/reddit/subreddit.py in _fetch(self)
    514 
    515     def _fetch(self):
--> 516         data = self._fetch_data()
    517         data = data["data"]
    518         other = type(self)(self._reddit, _data=data)

~/PycharmProjects/praw/praw/models/reddit/subreddit.py in _fetch_data(self)
    511         name, fields, params = self._fetch_info()
    512         path = API_PATH[name].format(**fields)
--> 513         return self._reddit.request("GET", path, params)
    514 
    515     def _fetch(self):

~/PycharmProjects/praw/praw/reddit.py in request(self, method, path, params, data, files)
    661                 files=files,
    662                 params=params,
--> 663                 timeout=self.config.timeout,
    664             )
    665         except BadRequest as exception:

~/.virtualenvs/praw/venv/lib/python3.7/site-packages/prawcore/sessions.py in request(self, method, path, data, files, json, params, timeout)
    334             params=params,
    335             timeout=timeout,
--> 336             url=url,
    337         )
    338 

~/.virtualenvs/praw/venv/lib/python3.7/site-packages/prawcore/sessions.py in _request_with_retries(self, data, files, json, method, params, timeout, url, retry_strategy_state)
    233             retry_strategy_state,
    234             timeout,
--> 235             url,
    236         )
    237 

~/.virtualenvs/praw/venv/lib/python3.7/site-packages/prawcore/sessions.py in _make_request(self, data, files, json, method, params, retry_strategy_state, timeout, url)
    193                 json=json,
    194                 params=params,
--> 195                 timeout=timeout,
    196             )
    197             log.debug(

~/.virtualenvs/praw/venv/lib/python3.7/site-packages/prawcore/rate_limit.py in call(self, request_function, set_header_callback, *args, **kwargs)
     34         self.delay()
     35         kwargs["headers"] = set_header_callback()
---> 36         response = request_function(*args, **kwargs)
     37         self.update(response.headers)
     38         return response

~/.virtualenvs/praw/venv/lib/python3.7/site-packages/prawcore/requestor.py in request(self, timeout, *args, **kwargs)
     53             return self._http.request(*args, timeout=timeout, **kwargs)
     54         except Exception as exc:
---> 55             raise RequestException(exc, args, kwargs)

RequestException: error with request Timeout value connect was 16, but it must be an int, float or None.
```

**System Info**
 - OS: MacOS 10.14.6
 - Python: 3.7.7
 - PRAW Version: 7.0.0dev0



Discussion:

Resolving patch:
diff --git a/praw/config.py b/praw/config.py
--- a/praw/config.py
+++ b/praw/config.py
@@ -139,3 +139,16 @@ def _initialize_attributes(self):
 
         for required_attribute in ("oauth_url", "reddit_url", "timeout"):
             setattr(self, required_attribute, self._fetch(required_attribute))
+
+        for attribute, conversion in {"timeout": int}.items():
+            try:
+                setattr(self, attribute, conversion(getattr(self, attribute)))
+            except ValueError:
+                raise ValueError(
+                    "An incorrect config type was given for option {}. The "
+                    "expected type is {}, but the given value is {}.".format(
+                        attribute,
+                        conversion.__name__,
+                        getattr(self, attribute),
+                    )
+                )


Test patch:
diff --git a/tests/unit/test_reddit.py b/tests/unit/test_reddit.py
--- a/tests/unit/test_reddit.py
+++ b/tests/unit/test_reddit.py
@@ -53,6 +53,15 @@ def test_info__invalid_param(self):
 
         assert excinfo.match("(?i)mutually exclusive")
 
+    def test_invalid_config(self):
+        with pytest.raises(ValueError) as excinfo:
+            Reddit(timeout="test", **self.REQUIRED_DUMMY_SETTINGS)
+        assert (
+            excinfo.value.args[0]
+            == "An incorrect config type was given for option timeout. The "
+            "expected type is int, but the given value is test."
+        )
+
     def test_info__not_list(self):
         with pytest.raises(TypeError) as excinfo:
             self.reddit.info("Let's try a string")