-
Notifications
You must be signed in to change notification settings - Fork 584
-
Notifications
You must be signed in to change notification settings - Fork 584
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
Show falsifying keyword arguments in the same order as the arguments #2913
Comments
I'd be happy to accept a patch the patch above, as well as stopping hypothesis/hypothesis-python/src/hypothesis/strategies/_internal/collections.py Lines 233 to 239 in 3d5761e
IMO this made sense when we supported earlier versions of Python for consistency across versions, as the database requires a consistent order of keys, but as definition order is reliably preserved on Python 3.6+ we can unconditionally |
OK. Should these be separate pull requests? |
I think combining them makes sense; with |
Once again procrastination proves to be a winning strategy for me. |
Falsifying examples are shown with positional arguments converted to keyword arguments. However, these are sorted in alphabetical order. This can be confusing. It would be better if the arguments were shown in the original order.
For example:
gives
I dug into it. Hypothesis internally converts the entire argument spec into a single strategy, and converts positional arguments into keyword arguments where possible.
The issue seems to be that fixed_dictionaries does not maintain key order for normal dictionaries. I'm not sure why this is the case, since dictionaries are supposed to be ordered since Python 3.6. Supposing that isn't going to change, however, I think this can be fixed by explicitly passing an OrderedDict
If this weren't the case, I believe this would just work as expected, except there is also an oddity where the keyword arguments are actually reversed for some reason here. I'm not entirely clear about that logic, but I guess it is supposed to handle the case where one argument to the
zip
is longer than the other (if so, it can easily be fixed by using an additional reversed on the zip).In short, this patch fixes the issue
Although (to me at least), making fixed_dictionaries not sort normal dicts would be preferable.
The text was updated successfully, but these errors were encountered: