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

Parameter name clash in extra.django.from_model #2369

Closed
DanLipsitt opened this issue Mar 10, 2020 · 1 comment · Fixed by #2372
Closed

Parameter name clash in extra.django.from_model #2369

DanLipsitt opened this issue Mar 10, 2020 · 1 comment · Fixed by #2372
Assignees
Labels
bug something is clearly wrong here

Comments

@DanLipsitt
Copy link

from_model's first argument is model:

def from_model(
model: Type[dm.Model], **field_strategies: Union[st.SearchStrategy, InferType]
) -> st.SearchStrategy:

This leads to an error when trying to write a strategy for a class that has a field named model. For example:

from django.db.models import Model, CharField
class Car(Model):
    model = CharField(help_text="The model of the car.")

car_strategy = from_model(Car, model='Mustang')

This will result in the following error:

TypeError: from_model() got multiple values for argument 'model'

Perhaps the first argument to from_model could be named _model or _hypothesis_model or something like that?

@Zac-HD Zac-HD added the bug something is clearly wrong here label Mar 11, 2020
@Zac-HD
Copy link
Member

Zac-HD commented Mar 11, 2020

Ah, we had the same problem with builds() (#1106), which was fixed by manual validation of *args - it's inelegant, but fixes the problem.

In Python 3.8 (or later), we can instead use a named positional-only argument... but that's years away. Until then we can patch the __signature__ to fix our docs, like #2345, and get better introspection on new Pythons for free.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug something is clearly wrong here
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants