improve typing for `await Band.objects().first()`
Related to https://github.com/piccolo-orm/piccolo/issues/561
When doing this query:
band = await Band.objects().first()
MyPy now knows the response is t.Optional[Band]. This was possible by using Generic and TypeVar from Python's typing module.
Codecov Report
Merging #562 (5690fa1) into master (aee9388) will increase coverage by
0.05%. The diff coverage is96.01%.
@@ Coverage Diff @@
## master #562 +/- ##
==========================================
+ Coverage 91.25% 91.30% +0.05%
==========================================
Files 107 108 +1
Lines 7317 7383 +66
==========================================
+ Hits 6677 6741 +64
- Misses 640 642 +2
| Impacted Files | Coverage Δ | |
|---|---|---|
| piccolo/apps/asgi/commands/new.py | 73.43% <ø> (ø) |
|
| piccolo/query/mixins.py | 94.59% <ø> (-0.08%) |
:arrow_down: |
| piccolo/query/methods/select.py | 97.90% <91.07%> (-1.70%) |
:arrow_down: |
| piccolo/query/base.py | 87.50% <93.75%> (+0.80%) |
:arrow_up: |
| piccolo/query/proxy.py | 94.28% <94.28%> (ø) |
|
| piccolo/apps/migrations/commands/clean.py | 93.93% <100.00%> (ø) |
|
| piccolo/custom_types.py | 100.00% <100.00%> (ø) |
|
| piccolo/engine/postgres.py | 91.28% <100.00%> (ø) |
|
| piccolo/engine/sqlite.py | 92.08% <100.00%> (ø) |
|
| piccolo/query/methods/alter.py | 90.12% <100.00%> (+0.04%) |
:arrow_up: |
| ... and 10 more |
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.
This pull request introduces 3 alerts when merging 0194ff9f88a577f3e9467a2514db61fe2e813224 into cacf7c507f20d153bd40306bf250816e6edb0512 - view on LGTM.com
new alerts:
- 3 for First argument to super() is not enclosing class
I propose to use TypeVar("ClassT", bound="Class") instead of Self, since Self is relatively new and not supported by mypy/pycharm, afaik.
Remaining tasks:
- [x] There's a small bug causing the CockroachDB tests to fail which needs fixing.
- [x] The SQLite test for frozen queries is sometimes failing - it's a fragile test, as it depends on timing code.
- [x] We added a
proxyfunction in a few places - we might be able to make this more DRY.