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

Deprecate floating-point values for size arguments #1619

Closed
Zac-HD opened this issue Oct 3, 2018 · 3 comments
Closed

Deprecate floating-point values for size arguments #1619

Zac-HD opened this issue Oct 3, 2018 · 3 comments

Comments

@Zac-HD
Copy link
Member

Zac-HD commented Oct 3, 2018

@check_function
def check_valid_size(value, name):
"""Checks that value is either unspecified, or a valid non-negative size
expressed as an integer/float.
Otherwise raises InvalidArgument.
"""
if value is None:
return
check_type(integer_types + (float,), value)

Sizes - the number of elements in a collection, bounded by min_size and max_size arguments, should always be integers. However, we currently also accept floats for these arguments! We should replace the check_type(integer_types + (float,), value) with

if isinstance(value, float):
    note_deprecation(...)
else:
    check_type(integer_types, value) 

And then write a test in hypothesis-python/tests/cover/test_validation.py that uses @checks_deprecated_behaviour, passes max_size=5.0 to lists(), and checks that the resulting lists are at most five elements long.

Finally, we should update the type hints for average_size arguments to # type: None as None is the only non-deprecated value.

@mridul2899
Copy link

mridul2899 commented Oct 3, 2018

Hey Zac!
I'm Mridul, a beginner in the field of open source development. I think I can resolve this issue. Can you assign this issue to me?

@Zac-HD
Copy link
Member Author

Zac-HD commented Oct 3, 2018

Sure! It's all yours for the next week - just @-mention me if you have any more questions, and welcome to Hypothesis ✨

@math2001
Copy link
Contributor

math2001 commented Oct 10, 2018

max_size=5.0 to lists(), and checks that the resulting lists are at most five elements long.

What should happen if someone passes 5.2 for example? I've quickly tested, and it seems to do some sort of math.ceil.

That seems to be handled on #1634 though, so should I just test "whole" float numbers for this issue?

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

3 participants