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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(feat): Support Money as Type #22

Closed
wants to merge 3 commits into from
Closed

chore(feat): Support Money as Type #22

wants to merge 3 commits into from

Conversation

yezz123
Copy link
Collaborator

@yezz123 yezz123 commented Mar 28, 2023

from pydantic import BaseModel, ValidationError
from pydantic_extra_types import CurrencyCode
import pytest

class Product(BaseModel):
    name: str
    price: float
    code: CurrencyCode

example = [
     {
          "name": "Apple",
          "price": 1.99,
          "code": "USD"
     },
     {
          "name": "Banana",
          "price": 2.99,
          "code": "EUR"
     },
     {
          "name": "Orange",
          "price": 3.99,
          "code": "GBP"
     },
     {
          "name": "Pineapple",
          "price": 4.99,
          "code": "Us"
     },
]

assert Product(**example[0]).code == "USD"
assert Product(**example[1]).code == "EUR"
assert Product(**example[2]).code == "GBP"

def test_invalid():
     with pytest.raises(ValidationError):
          Product(**example[3])

print(f"This currency code is not valide: {example[3]['code']}")

cc @samuelcolvin this following one also ready for review 馃憤馃徎

@yezz123 yezz123 added the Types label Mar 28, 2023
@yezz123 yezz123 self-assigned this Mar 28, 2023
@yezz123
Copy link
Collaborator Author

yezz123 commented Mar 28, 2023

Similar to this one's logic #14

Copy link
Member

@samuelcolvin samuelcolvin left a comment

Choose a reason for hiding this comment

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

this will likely need a lot more work, but we need to agree on the below point first.

@@ -0,0 +1,1468 @@
"""all supported currencies, Data about currencies is taken from https://github.com/sebastianbergmann/money"""
Copy link
Member

Choose a reason for hiding this comment

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

this repo is archived.

If we're to support this type, we need:

  1. a reliable up-to-date source
  2. a way to update our list with a script from the source.

@yezz123
Copy link
Collaborator Author

yezz123 commented May 7, 2023

I will close this and support pycountry as we have currencies also supported

@yezz123 yezz123 closed this May 7, 2023
@yezz123 yezz123 deleted the type/money branch October 5, 2023 17:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants