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

add typing support to make and prepare #213

Merged
merged 1 commit into from
Jun 22, 2021
Merged

add typing support to make and prepare #213

merged 1 commit into from
Jun 22, 2021

Conversation

stohrendorf
Copy link
Contributor

This adds proper typing for enabling at least PyCharm to support proper code completion and silence type warnings in baker.make and baker.prepare calls.

  1. Before, PyCharm was always complaining about the first parameter to baker.make not being of Type[ModelBase], which is correct, as we're passing derived models, not the ModelBase.
  2. Before, PyCharm was unable to provide code completion for the resulting instance. Although this is still not perfect because of the _quantity parameter, it now correctly lists fields and methods for the passed model class besides the list interface. I.e., we do not need to write mocked_model: SomeModel = baker.make(SomeModel) every time, and instead can rely on automatic type deduction now without explicitly specifying the model type of the variable.

Copy link
Collaborator

@timjklein36 timjklein36 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the "base" class is not exactly correct (see inline comment). Otherwise the type union for the return looks fine (replacing the TypeVar with the correct base type).

model_bakery/baker.py Show resolved Hide resolved
@berinhard
Copy link
Member

Thanks for your PR @stohrendorf and @timjklein36 for the initial review!

Happy baking 🍰

@berinhard berinhard merged commit 5a2d9c5 into model-bakers:main Jun 22, 2021
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

Successfully merging this pull request may close these issues.

3 participants