Popular value constraint
See original GitHub issueHello! I’m creating this issue to see how people feels about choosing the most popular constrains so we can agree which one are more important/urgent, feel free also to comment improve the list if you feel like I’m missing something. I’m gonna create some categories as well for visibility
String Constraints
- Uuid
- Choice
- Language
- Locale
- Country
- Currency
Comparison Constraints
- EqualTo
- NotEqualTo
- IdenticalTo
- NotIdenticalTo
- LessThan
- GreaterThan
- Range
- DivisibleBy
The implementation I think should be something like:
passports: Annotated[List[str], Country[alpha3=True]],
age: Annotated[date, Range["1901-12-12", "2001-12-12"]],
pets: Annotated[int, GreaterThan[-1]],
bio: Annotated[Optional[str], Range[50, 500]],
Issue Analytics
- State:
- Created 3 years ago
- Reactions:3
- Comments:11 (10 by maintainers)
Top Results From Across the Web
6 Commonly Used Different kinds of SQL Constraints - eduCBA
Different Kinds of SQL Constraints · 1. NOT NULL Constraint. This constraint is used when you do not want any value in that...
Read more >Keys and constraints commonly used in SQL - Launch School
Keys and constraints declare what values can be used for table columns. A general overview of common keys and constraints such as, not...
Read more >SQL Constraints - w3resource
The SQL CONSTRAINTS are an integrity which define some conditions that restricts the column to remain true while inserting or updating or ...
Read more >Exploring the different constraints in SQL Server
The PRIMARY KEY constraint in SQL Server is a popular choice among database professionals for implementing unique values in a relational ...
Read more >Constraints in SQL Server: SQL NOT NULL, UNIQUE and SQL ...
This article explains the useful constraints SQL NOT NULL, Unique and Primary Key constraints in SQL Server examples with user cases.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Those dodgy nootropics seem to be doing you well @leycec! 💊 Funnily enough, that project was just part of a school course back when I was learning Python…so I wouldn’t really call myself a data validation connoisseur. Having said that, I’d still love to help where I can. 👍
This looks great! A mypy-compliant constraints package would certainly be amazing, and a sprinkle of bear puns makes it even better 😃 🐻 It’s definitely something that I would love to use.
If this is going to be a seperate project (which it seems like it will), I have a few suggestions from our experience with the beartype project which you might find interesting.
Either way, whatever happens, I’ll still be here to package the project when you need me. 📦 Thanks for all your work on the beartype project @leycec! You’ve done an amazing job.
Also hi 👋 @Saphyel. It’s always great to see a fellow Londoner! 🇬🇧 I hope the chilly nightfall is treating you well.
Boom-shaka! 🔥 💥 🤯
@beartype
now supports arbitrary caller-defined data validators. Thus ends a year-long journey culminating in the complete loss of all hair from my head, which we take a sober moment to mourn.Everyone may now efficiently validate the internal structure of arbitrarily complex scalars, data structures, and third-party objects with PEP-compliant type hints that preserve everything you secretly love about fat bears, luscious berries, hot Spring weather, and valid app data.
Syntax
@beartype
-decorated callables may now be annotated by type hints of the formtyping.Annotated[{cls}, beartype.vale.Is[lambda obj: {test_expr1}], ..., beartype.vale.Is[lambda obj: {test_exprN}]]
, where:{cls}
is any arbitrary class (e.g.,str
,numpy.ndarray
).{test_expr1}
is any arbitrary expression evaluating to a boolean (e.g.,len(obj) <= 80
,obj.dtype == np.dtype(np.float64)
).{test_exprN}
is any arbitrary expression evaluating to a boolean, too.Syntax: it’s no sin and we don’t charge tax.
Example 1: Make It So, Ensign NumPy!
Computational geometry example or it didn’t happen, so let’s validate a passed object as a two-dimensional NumPy array of floats of arbitrary precision:
DSL: It’s Not Just a Telecom Acronym Anymore
beartype.vale.Is
also supports a rich domain-specific language (DSL) enabling new validators to be synthesized from existing validators with overloaded set operators, including:~beartype.vale.Is[lambda obj: {test_expr}]
, equivalent tobeartype.vale.Is[lambda obj: not {test_expr}]
.beartype.vale.Is[lambda obj: {test_expr1}] & beartype.vale.Is[lambda obj: {test_expr2}]
, equivalent tobeartype.vale.Is[lambda obj: {test_expr1} and {test_expr2}]
.beartype.vale.Is[lambda obj: {test_expr1}] | beartype.vale.Is[lambda obj: {test_expr2}]
, equivalent tobeartype.vale.Is[lambda obj: {test_expr1} or {test_expr2}]
.Example 2: Validate My Strings or GTFO
Nonsensical string matching example or it didn’t happen, so let’s validate a passed object as a string either of at least 80 characters or both quoted and suffixed by a period. Look, it doesn’t matter. Just do it already,
@beartype
!There’s No Catch, I Swear and I Cannot Tell a Lie
Everything above fully complies with PEP 593 and thus requires Python ≥ 3.9. See
help(beartype.vale.Is)
in your favourite Python REPL (…which is, of course, Jupyter Lab, because I see that you are an end user of culture) for full usage instructions, complete with real-world examples.Thus ends my last hair follicle. 👨🦲