BeanieODM / beanie

Asynchronous Python ODM for MongoDB
http://beanie-odm.dev/
Apache License 2.0
1.94k stars 203 forks source link

Fix: FindInterface type-hints break on View models #819

Closed GuyGooL5 closed 6 months ago

GuyGooL5 commented 7 months ago

This PR adds a new TypeVar for View just like DocType, and is used in FindInterface to bind it for each model with their respective model type.

It fixes a bug where find operations type-checks break when used with View descendants. For example, see this issue.

roman-right commented 6 months ago

Hi @GuyGooL5 , Could you please run pre-commit against your changes? Thank you for the PR!

GuyGooL5 commented 6 months ago

Hi @roman-right, unfortunately I've found that my solution isn't all-inclusive and there are many edge cases, I'm drafting this PR and will work on it.

roman-right commented 6 months ago

Hi @GuyGooL5 , Yes sure. Thank you for your work!

GuyGooL5 commented 6 months ago

@roman-right I hope that's enough for a fix. I tested the type inference in VSCode and it seems to work, is there maybe a test I can implement to future-proof it from a static-type checker's perspective?

roman-right commented 6 months ago

Hi @GuyGooL5 , Thank you for the PR! I'll check it this week

roman-right commented 6 months ago

Hi @GuyGooL5 , Thank you for your work. Merged. It will be published in a few days

GuyGooL5 commented 6 months ago

Great news, thanks.