falconry / falcon

The no-magic web data plane API and microservices framework for Python developers, with a focus on reliability, correctness, and performance at scale.
https://falcon.readthedocs.io/en/stable/
Apache License 2.0
9.53k stars 945 forks source link

Support pathlib.Path for directory in `App.add_static_route(...)` #1962

Closed vytas7 closed 3 years ago

vytas7 commented 3 years ago

It has become trendy to support pathlib.Path objects in addition to, or even instead of, str where the argument in question denotes a filesystem path.

We could support and document directory of type Path in App.add_static_route(...).

It currently already works implicitly via our invocation of os.path.normpath in Python 3.6+, but explodes on 3.5.

We could either fix this for 3.5, or wait for Falcon 4.0 which will presumably drop 3.5 support, and then just document the implicit support, backed by unit tests.

CaselIT commented 3 years ago

An alternative is to just support it for 3.6+ in v3. Personally I don't think it makes much sense to do something special for 3.5, since it's very marginal at this point

vgerak commented 3 years ago

@vytas7 created a PR that should handle this issue.

It already works, as you mentioned. The fix for py3.5 is a trivial cast to str(), so having it does not leave any significant technical debt imho.

Included a simple test with a Path directory (without the str() cast it breaks in py3.5, as expected).