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

Setting fixed length to a string #41

Open
ahopkins opened this issue May 2, 2019 · 4 comments
Open

Setting fixed length to a string #41

ahopkins opened this issue May 2, 2019 · 4 comments
Assignees
Labels
bug Something isn't working enhancement New feature or request

Comments

@ahopkins
Copy link

ahopkins commented May 2, 2019

  • middle version: 0.2.2
  • Python version: 3.7.3
  • Operating System: Alpine Linux v3.9

Description

Set a length requirement for a str

What I Did

class Foo(middle.Model):
    bar: str = middle.field(min_length=4, max_length=4)
ValueError: The 'min_length' keyword value must not be equal or greater than the 'max_length' keyword value. 

This seems like it should be possible. Or, perhaps:

bar: str = middle.field(length=4)
@ahopkins
Copy link
Author

ahopkins commented May 2, 2019

bar: str = middle.field(length=4)

This is valid. I did not check before posting this. Perhaps an error message in this case would be helpful?

ValueError: 'min_length' is equal to 'max_length'. Instead, consider using 'length'.

@vltr
Copy link
Owner

vltr commented Jun 18, 2019

@ahopkins well, length should not be a valid keyword (I think it's derived from attrs), only min_length and max_length, as described in the OpenAPI 3 specs. Perhaps the length=X could be a shorthand for min_length=X, max_length=X as well?

@vltr vltr self-assigned this Jun 18, 2019
@vltr vltr added enhancement New feature or request bug Something isn't working labels Jun 18, 2019
@vltr vltr added this to To Do in middle 0.3.0 via automation Jun 18, 2019
@ahopkins
Copy link
Author

I think it should be. Seems like a very useful shorthand. Especially if you are going to drop attrs as a dependency.

@ahopkins
Copy link
Author

But... that's just one man's opinion 😉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
middle 0.3.0
  
To Do
Development

No branches or pull requests

3 participants
@ahopkins @vltr and others