Skip to content

Commit

Permalink
chore: Replace conint and constr with new types (#442)
Browse files Browse the repository at this point in the history
* chore: Replace conint and constr with new types

* Fix ruff issues

---------

Co-authored-by: Victor Shia <[email protected]>
  • Loading branch information
vshia and vshia authored Sep 26, 2024
1 parent 1d7daac commit 56f77e0
Show file tree
Hide file tree
Showing 5 changed files with 406 additions and 361 deletions.
2 changes: 2 additions & 0 deletions python/src/functions/generate_treasury_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ def process_event(payload: ProjectLambdaPayload, logger: structlog.stdlib.BoundL
file=json_file,
)


def download_output_file(
s3_client: S3Client,
output_file: IO[bytes],
Expand Down Expand Up @@ -299,6 +300,7 @@ def download_output_file(
highest_row_num = OUTPUT_STARTING_ROW - 1
return highest_row_num


def get_existing_output_metadata(
s3_client,
organization: OrganizationObj,
Expand Down
132 changes: 111 additions & 21 deletions python/src/schemas/custom_types.py
Original file line number Diff line number Diff line change
@@ -1,54 +1,144 @@
from typing_extensions import Annotated
from pydantic import BaseModel, Field, PlainSerializer
from pydantic import Field, StringConstraints, PlainSerializer
from decimal import Decimal


CustomDecimal_16Digits = Annotated[
Decimal, Field(
max_digits=16,
decimal_places=2
), PlainSerializer(
Decimal,
Field(max_digits=16, decimal_places=2),
PlainSerializer(
lambda x: f"{float(x):.2f}",
return_type=str,
),
]

CustomDecimal_15Digits = Annotated[
Decimal, Field(
max_digits=15,
decimal_places=2
), PlainSerializer(
Decimal,
Field(max_digits=15, decimal_places=2),
PlainSerializer(
lambda x: f"{float(x):.2f}",
return_type=str,
),
]

CustomDecimal_13Digits = Annotated[
Decimal, Field(
max_digits=13,
decimal_places=2
), PlainSerializer(
Decimal,
Field(max_digits=13, decimal_places=2),
PlainSerializer(
lambda x: f"{float(x):.2f}",
return_type=str,
),
]

CustomDecimal_12Digits = Annotated[
Decimal, Field(
max_digits=12,
decimal_places=2
), PlainSerializer(
Decimal,
Field(max_digits=12, decimal_places=2),
PlainSerializer(
lambda x: f"{float(x):.2f}",
return_type=str,
),
]

CustomDecimal_7Digits = Annotated[
Decimal, Field(
max_digits=7,
decimal_places=2
), PlainSerializer(
Decimal,
Field(max_digits=7, decimal_places=2),
PlainSerializer(
lambda x: f"{float(x):.2f}",
return_type=str,
),
]

CustomInt_GE1 = Annotated[int, Field(ge=1)]
CustomInt_GE0_LELARGE = Annotated[int, Field(ge=0, le=999999999)]
CustomInt_GE0_LELARGE2 = Annotated[int, Field(ge=0, le=9999999999)]
CustomInt_GE0_LELARGE3 = Annotated[int, Field(ge=0, le=99999999999)]
CustomInt_GE0_LELARGE4 = Annotated[int, Field(ge=0, le=999999999999)]

CustomStr_MIN1 = Annotated[
str,
StringConstraints(
strip_whitespace=True,
min_length=1,
),
]

CustomStr_MIN1_MAX100 = Annotated[
str,
StringConstraints(
strip_whitespace=True,
min_length=1,
max_length=100,
),
]

CustomStr_MIN1_MAX10 = Annotated[
str,
StringConstraints(
strip_whitespace=True,
min_length=1,
max_length=10,
),
]

CustomStr_MIN1_MAX20 = Annotated[
str,
StringConstraints(
strip_whitespace=True,
min_length=1,
max_length=20,
),
]

CustomStr_MIN12_MAX12 = Annotated[
str,
StringConstraints(
strip_whitespace=True,
min_length=12,
max_length=12,
),
]

CustomStr_MIN9_MAX9 = Annotated[
str,
StringConstraints(
strip_whitespace=True,
min_length=9,
max_length=9,
),
]

CustomStr_MIN1_MAX3000 = Annotated[
str,
StringConstraints(
strip_whitespace=True,
min_length=1,
max_length=3000,
),
]

CustomStr_MIN1_MAX5 = Annotated[
str,
StringConstraints(
strip_whitespace=True,
min_length=1,
max_length=5,
),
]

CustomStr_MIN1_MAX40 = Annotated[
str,
StringConstraints(
strip_whitespace=True,
min_length=1,
max_length=40,
),
]

CustomStr_MIN1_MAX80 = Annotated[
str,
StringConstraints(
strip_whitespace=True,
min_length=1,
max_length=80,
),
]
Loading

0 comments on commit 56f77e0

Please sign in to comment.