-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
_do_execute
(database function) could be more precisely typed with better support for ParamSpec
#12312
Comments
Which seems to be python/mypy#11847, according to @squahtx |
related: #11711 |
Blocked on #12585 |
I've just given this a quick try. I was a bit surprised that we need to include
I was then surprised by the next error from looking at
synapse/synapse/storage/database.py Lines 341 to 352 in a50fb41
This is again consistent with PEP 612:
Given that this is already caught at runtime, I'd be inclined to type-ignore this. |
Additionally: This doesn't actually give us a huge amount of type safety. Using a ParamSpec allows us to ensure that the There are four call sites at present, and none of them really have those meaningful annotations AFAICS. execute and executemanysynapse/synapse/storage/database.py Lines 332 to 336 in a50fb41
execute_batchsynapse/synapse/storage/database.py Lines 299 to 310 in a50fb41
Here the lambda expression has no annotations. Proof by example:
It's also worth noting that the stubs for
This is using the locked version of types-psycopg2, but it's no stricter in the latest release (2.9.13). execute_valuesVery similar to execute_batch. synapse/synapse/storage/database.py Lines 315 to 330 in a50fb41
The underlying postgres function has a few more annotations, but not any that would give us more checking.
|
The next version of mypy will include a fix for this: python/mypy#12668 |
Good to know. I found python/mypy#11826 by searching, but assumed that the behaviour there was intentional. |
I'm not sure this gives us a huge amount of type safety, see this comment: #12312 (comment) In any case, it's a nice bit of practice with `ParamSpec`.
I'm not sure this gives us a huge amount of type safety, see this comment: #12312 (comment) In any case, it's a nice bit of practice with `ParamSpec`.
Sprouted from #12311.
Once Mypy supports Concatenate, it could be written as
so long as we also pass kwargs.
The text was updated successfully, but these errors were encountered: