question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

More exotic types

See original GitHub issue

Hi,

At my company we would like to migrate to your package, but we need more types out of the box. Below you can find list of additional types and validators and I like to discuss with you what do you think:

  1. Min and max length validators for list type, maybe something like conlist(type_=..., min_length=..., max_length=...). Of course I can implement length validation using validator decorator, but it’s too complex to share as common type for company needs.
  2. (Done #175) Decimal type not supported at all. Also we would like to have validators for minimum, maximum, maximum digits and decimal places like in Django (https://github.com/django/django/blob/master/django/forms/fields.py#L322, https://github.com/django/django/blob/master/django/core/validators.py#L388).
  3. (Done #166) Float type: minimum and maximum validators.
  4. String type:
    1. (Done #163) We need additional strip_whitespace argument in constr to strip whitespaces, just value.strip(). In my opinion it’s common practice for validation libraries to have this option.
    2. Also I would like to discuss with you coerce logic (https://github.com/samuelcolvin/pydantic/blob/master/pydantic/validators.py#L30). Why it supports only for float, int and decimal types? Can we use logic which already implemented for dict and list types (https://github.com/samuelcolvin/pydantic/blob/master/pydantic/validators.py#L83)?
  5. (Done #167) UUID type version validation, just value.version == ....

If you are okay with my proposals, then I will create a few PRs for each my proposal.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:10 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
samuelcolvincommented, May 25, 2019

This is not what conlist is for, conlist is for controlling the size of the outer list.

You can achieve what you’re looking for here either with custom validators, a Point type that implements it’s own validation, or with a simple tuple:

from typing import List, Tuple, Union
from pydantic.dataclasses import dataclass

@dataclass
class Geometry:
    type: str
    coordinates: List[Union[Tuple[float, float], Tuple[float, float, float]]]

print(Geometry(type='Polygon', coordinates=[[0, 0], [10, 10], [10, 0, 0.5]]))

If you have anymore questions, please create a new issue.

0reactions
alex-lechnercommented, May 25, 2019

Oh I’m sorry I forgot to elaborate on my issue a bit more. In my case, I need to validate geometry objects based on the GeoJSON Specification. In my example above I validate a Polygon object. The structure of the Polygon in a GeoJSON has to look like this:

{
  "type": "Polygon",
  "coordinates": [
    [
      [0, 0], [10, 10], [10, 0], [0, 0]
    ]
  ]
}

As you can see the coordinates are a nested list with an exterior Part (second list) and Points (lists within the second list). The order of a Point described by the Geojson is [longitude, latitude, elevation]. So a Point can only have either 2 or 3 values in a list but not more or less. That’s why conlist might come in handy because the conlist would set a constraint on the list/array object.

Would you accept a PR for GeoJSON support? Also for the conlist?

Read more comments on GitHub >

github_iconTop Results From Across the Web

10 Most Exotic Weed Strains 2022
The more exotic types have different effects, they can also be stronger and have a different smell and even a different color of...
Read more >
Types of Exotic Pets
There are several categories of exotic pet species: Amphibians. Most need tanks with both water and “land” for your pet to feel completely ......
Read more >
EVEN MORE Types of Exotic Cat Breeds
EVEN MORE Types of Exotic Cat Breeds · #9: LaPerm · #8: Sphynx · #7: Devon Rex · #6: Maine Coon · #5:...
Read more >
More exotic types · Issue #161 · pydantic ...
Below you can find list of additional types and validators and I like to discuss with you what do you think:
Read more >
5 Exotic Butterfly Species from Around the World
Butterflies are some of the most beautiful creatures in the world, and many exotic butterfly species come in a wide variety of dazzling ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found