Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stub for generated Models #9

Open
alecandido opened this issue May 31, 2023 · 3 comments
Open

Stub for generated Models #9

alecandido opened this issue May 31, 2023 · 3 comments

Comments

@alecandido
Copy link
Member

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
Copy link
Member

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

@alecandido
Copy link
Member Author

alecandido commented May 31, 2023

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
Copy link
Member

Fine, then go for it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants