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

Question: What about using Annotated for types? #2

Open
hasansezertasan opened this issue Feb 12, 2024 · 1 comment
Open

Question: What about using Annotated for types? #2

hasansezertasan opened this issue Feb 12, 2024 · 1 comment
Assignees
Labels
enhancement New feature or request question Further information is requested

Comments

@hasansezertasan
Copy link
Owner

hasansezertasan commented Feb 12, 2024

Is your feature request related to a problem? Please describe.
In SQLAlchemy, we constantly use String(64), String(128), etc. What about providing these types in a more pythonic way, a standardized way?

Describe the solution you'd like

I already have some type annotations that I use with SQLAlchemy:

from typing import Annotated

from sqlalchemy import DECIMAL, String, Unicode
from sqlalchemy.orm import mapped_column
from sqlalchemy_utils import EmailType, IPAddressType, PhoneNumberType, URLType

PostalCode = Annotated[
    str,
    mapped_column(
        type_=String(5),
        info={
            "label": "Postal Code",
            "description": "The postal code of the address.",
            "example": "12345",
        },
    ),
]
"""Postal Code Type."""
Latitude = Annotated[float, mapped_column(type_=DECIMAL(precision=10, scale=8))]
"""Latitude Type."""
Longitude = Annotated[float, mapped_column(type_=DECIMAL(precision=11, scale=8))]
"""Longitude Type."""
Money = Annotated[float, mapped_column(type_=DECIMAL(precision=18, scale=9))]
"""Money Type."""
PhoneNumber = Annotated[str, mapped_column(type_=Unicode(64))]
"""Phone Number Type."""
EmailAddress = Annotated[str, mapped_column(type_=EmailType)]
"""Email Address Type."""
String64 = Annotated[str, mapped_column(type_=String(64))]
"""String 64 Type."""
String128 = Annotated[str, mapped_column(type_=String(128))]
"""String 128 Type."""
String256 = Annotated[str, mapped_column(type_=String(256))]
"""String 256 Type."""
String512 = Annotated[str, mapped_column(type_=String(512))]
"""String 512 Type."""
String1024 = Annotated[str, mapped_column(type_=String(1024))]
"""String 1024 Type."""
String2048 = Annotated[str, mapped_column(type_=String(2048))]
"""String 2048 Type."""
UUIDString = Annotated[str, mapped_column(type_=String(36))]
"""UUID String Type."""
IPAddress = Annotated[str, mapped_column(type_=IPAddressType(64))]
"""IP Address Type."""
URL = Annotated[str, mapped_column(type_=URLType)]
"""URL Type."""

Describe alternatives you've considered
kvesteri/sqlalchemy-utils: Various utility functions and datatypes for SQLAlchemy.

Additional context
Maybe some standard enumerations?

@hasansezertasan hasansezertasan added the enhancement New feature or request label Feb 12, 2024
@hasansezertasan hasansezertasan self-assigned this Feb 12, 2024
@hasansezertasan hasansezertasan changed the title What about types? What about using Annotated for types? Feb 17, 2024
@hasansezertasan
Copy link
Owner Author

Pydantic also has support for Annotated, see:

I'm still learning 🤣.

@hasansezertasan hasansezertasan changed the title What about using Annotated for types? Question: What about using Annotated for types? Mar 16, 2024
@hasansezertasan hasansezertasan added the question Further information is requested label Mar 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request question Further information is requested
Projects
None yet
Development

No branches or pull requests

1 participant