This release adds 4 new checks, a new flag, and a few bug fixes.
Add `simplify-fastapi-query` check (FURB175)
FastAPI will automatically pass along query parameters to your function, so you only need to use `Query()` when you use params other than `default`.
Bad:
python
app.get("/")
def index(name: str = Query()) -> str:
return f"Your name is {name}"
Good:
python
app.get("/")
def index(name: str) -> str:
return f"Your name is {name}"
Add `unreliable-utc-usage` check (FURB176)
Because naive `datetime` objects are treated by many `datetime` methods as local times, it is preferred to use aware datetimes to represent times in UTC.
This check affects `datetime.utcnow` and `datetime.utcfromtimestamp`.
Bad:
python
from datetime import datetime
now = datetime.utcnow()
past_date = datetime.utcfromtimestamp(some_timestamp)
Good:
python
from datetime import datetime, timezone
datetime.now(timezone.utc)
datetime.fromtimestamp(some_timestamp, tz=timezone.utc)
Add `no-implicit-cwd` check (FURB177)
If you want to get the current working directory don't call `resolve()` on an empty `Path()` object, use `Path.cwd()` instead.
Bad:
python
cwd = Path().resolve()
Good:
python
cwd = Path.cwd()
Add `--verbose` flag
This flag will spit out extra information about Refurb and related configuration info. Currently the `--verbose` flag will only print the enabled checks, though more information might be displayed in the future.
---
What's Changed
* Add `simplify-fastapi-query` check by dosisod in https://github.com/dosisod/refurb/pull/256
* Warn `datetime.{utcnow,utcfromtimestamp}` usages by sobolevn in https://github.com/dosisod/refurb/pull/259
* Do not run `isort` on `test/data` folder by sobolevn in https://github.com/dosisod/refurb/pull/264
* Add title and improve one fix by ChaoticRoman in https://github.com/dosisod/refurb/pull/265
* Improve coverage by dosisod in https://github.com/dosisod/refurb/pull/267
* Add `--verbose` flag, update documentation by dosisod in https://github.com/dosisod/refurb/pull/271
* Make `--verbose` output on a single line by dosisod in https://github.com/dosisod/refurb/pull/272
* Use `pip install -e .` in `Makefile` by sobolevn in https://github.com/dosisod/refurb/pull/260
New Contributors
* sobolevn made their first contribution in https://github.com/dosisod/refurb/pull/259
* ChaoticRoman made their first contribution in https://github.com/dosisod/refurb/pull/265
**Full Changelog**: https://github.com/dosisod/refurb/compare/v1.17.0...v1.18.0