Repository: sloria/environs

Issue:
env.path => pathlib.Path
```python
>>> env.path('C:\Users\whoami\Downloads')
WindowsPath('C:/Users/whoami/Downloads')
```

Discussion:

Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index fc89864..8c42879 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,12 @@
 
 ### 5.0.0 (unreleased)
 
+Features:
+
+- Add `env.path` ([#81](https://github.com/sloria/environs/issues/81)).
+  Thanks [umrashrf](https://github.com/umrashrf) for the suggestion.
+- Add type annotations.
+
 Other changes:
 
 - _Backwards-incompatible_: Drop support for Python 2. If you use Python 2,
diff --git a/environs.py b/environs.py
index a2dc4f6..a54bc5c 100644
--- a/environs.py
+++ b/environs.py
@@ -7,6 +7,7 @@ import re
 import typing
 from collections.abc import Mapping
 from urllib.parse import urlparse, ParseResult
+from pathlib import Path
 
 import marshmallow as ma
 from dotenv import load_dotenv
@@ -151,6 +152,12 @@ class URLField(ma.fields.URL):
         return urlparse(ret)
 
 
+class PathField(ma.fields.Str):
+    def _deserialize(self, value, *args, **kwargs) -> Path:
+        ret = super()._deserialize(value, *args, **kwargs)
+        return Path(ret)
+
+
 class Env:
     """An environment variable reader."""
 
@@ -167,6 +174,7 @@ class Env:
         json=_field2method(ma.fields.Field, "json", preprocess=_preprocess_json),
         datetime=_field2method(ma.fields.DateTime, "datetime"),
         date=_field2method(ma.fields.Date, "date"),
+        path=_field2method(PathField, "path"),
         timedelta=_field2method(ma.fields.TimeDelta, "timedelta"),
         uuid=_field2method(ma.fields.UUID, "uuid"),
         url=_field2method(URLField, "url"),


Test patch:
diff --git a/tests/test_environs.py b/tests/test_environs.py
index 22f7bdb..6b67a65 100644
--- a/tests/test_environs.py
+++ b/tests/test_environs.py
@@ -3,6 +3,7 @@ from __future__ import unicode_literals
 import uuid
 import datetime as dt
 import urllib.parse
+import pathlib
 from decimal import Decimal
 
 import dj_database_url
@@ -151,6 +152,11 @@ class TestCasting:
         res = env.url("URL")
         assert isinstance(res, urllib.parse.ParseResult)
 
+    def test_path_cast(self, set_env, env):
+        set_env({"PTH": "/home/sloria"})
+        res = env.path("PTH")
+        assert isinstance(res, pathlib.Path)
+
     @pytest.mark.parametrize("url", ["foo", "42", "foo@bar"])
     def test_invalid_url(self, url, set_env, env):
         set_env({"URL": url})
@@ -313,6 +319,7 @@ class TestDumping:
                 "INT": "42",
                 "DTIME": dtime.isoformat(),
                 "URLPARSE": "http://stevenloria.com/projects/?foo=42",
+                "PTH": "/home/sloria",
             }
         )
 
@@ -320,6 +327,7 @@ class TestDumping:
         env.int("INT")
         env.datetime("DTIME")
         env.url("URLPARSE")
+        env.path("PTH")
 
         result = env.dump()
         assert result["STR"] == "foo"
@@ -328,6 +336,8 @@ class TestDumping:
         assert type(result["DTIME"]) is str
         assert isinstance(result["URLPARSE"], str)
         assert result["URLPARSE"] == "http://stevenloria.com/projects/?foo=42"
+        assert isinstance(result["PTH"], str)
+        assert result["PTH"] == str(pathlib.Path("/home/sloria"))
 
     def test_env_with_custom_parser(self, set_env, env):
         @env.parser_for("url")