qiboteam / qibodb

Apache License 2.0
2 stars 0 forks source link

Stub for generated Models #9

Open alecandido opened 1 year ago

alecandido commented 1 year ago

Unfortunately, there is a bunch of duplication involved in inserting and retrieving information from the DB. You could get a grasp for this from a simple (official) example: https://www.mongodb.com/developer/languages/python/python-quickstart-fastapi/

This led to #8 and the ReadModel and UpdateModel creation.

Unfortunately, being dynamically generated, they are pretty useless for the static analyzers and the intellisense. For this reason, it would be useful to generate stub files (I won't generate code in Python files, especially in existing ones, to keep generated code separate from manually written one). https://mypy.readthedocs.io/en/stable/stubs.html

This is something that should be pretty simple to do automatically, starting with the stubgen CLI.

The only thing I'm not sure about is whether I want to commit to the repo or not. Contra: I don't like adding in Git and reviewing in GitHub generated files (even though they will look very close to the manually written ones) Pro: they will be available in development as well.

scarrazza commented 1 year ago

Do you really find this necessary? What is the real advantage in terms of maintenance?

alecandido commented 1 year ago

Static analysis support and autocompletion :)

It is not required, but I'm planning to run mypy as well in the CI, asap. Here it would not be a problem, because those types are only used to return, but using the results in the other packages would require exceptions (or just raise errors).

(mypy is pretty useful to catch errors, but only if you use type hints. But we're actually using them more and more)

In any case, this is not something I'm going to solve immediately. I just made sure not to raise errors here, running it manually.

scarrazza commented 1 year ago

Fine, then go for it.