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

convert Len to GroupedMetadata, add MinLen and MaxLen #21

Merged
merged 4 commits into from Sep 27, 2022

Conversation

samuelcolvin
Copy link
Contributor

Fairly self explanatory, should be backwards compatible.

I need MinLen and MaxLen in pydantic to convert fields arguments to constrains.

Copy link
Member

@Zac-HD Zac-HD left a comment

Choose a reason for hiding this comment

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

This is a good enough idea that I'm embarrassed I didn't think of it myself! Two comments:

  • needs to be documented in the README too
  • I have a little FUD around interpretation of the name Len when I'm going to use this for eg iterables on which it's an error to call len(). Best option IMO is to keep it and I'll add a note like "implementors may also apply this constraint in cases where len() cannot be used but the number of elements is still meaningful, such as iterators"

annotated_types/__init__.py Show resolved Hide resolved
@samuelcolvin
Copy link
Contributor Author

I'll add to the README.

We could call it Length, to make it a bit different to len()? But it doesn't help much.

@adriangb
Copy link
Contributor

How about NumItems?

@Zac-HD
Copy link
Member

Zac-HD commented Sep 27, 2022

I'm voting for the existing name, to be clear, just intending to add a one-sentence clarifying note!

@samuelcolvin
Copy link
Contributor Author

I'm voting for the existing name, to be clear, just intending to add a one-sentence clarifying note!

Agreed.

@samuelcolvin
Copy link
Contributor Author

This is a good enough idea that I'm embarrassed I didn't think of it myself!

I think we didn't have GroupedMetadata when Len was implemented, so a totally understandable omission.

needs to be documented in the README too

Done.

Please review.

@Zac-HD
Copy link
Member

Zac-HD commented Sep 27, 2022

This is a good enough idea that I'm embarrassed I didn't think of it myself!

I think we didn't have GroupedMetadata when Len was implemented, so a totally understandable omission.

Yeah, but I didn't notice when we added GroupedMetadata or even MinLen and MaxLen - it's the missed "should we apply this refactoring anywhere else" that I'm practicing. Not a big deal though 😸

@Zac-HD Zac-HD merged commit 9747ec3 into main Sep 27, 2022
@Zac-HD Zac-HD deleted the len-GroupedMetadata branch September 27, 2022 17:51
adriangb pushed a commit to adriangb/annotated-types that referenced this pull request May 31, 2023
…ted-types#21)

* convert Len to GroupedMetadata

* oops, fix test case

* simplify tests, fix linting

* add MinLen, MaxLen to README
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.

None yet

3 participants