Skip to content

Refactor 'NewType' as it no longer conforms to the typing spec #256

@mvanderlee

Description

@mvanderlee

Python is updating the Typing spec which causes Variable not allowed in type expression for types created with marshmallow_dataclass's NewType

microsoft/pyright#7268

The modern way is to use typing.Annotated. (Python >=3.9)

I propose deprecating NewType and adding Annotated support.

Example:

from typing import Annotated
import marshmallow.fields as mf
import marshmallow.validate as mv
from marshmallow_dataclass import dataclass

Url = Annotated[str, mf.Url]
Email = Annotated[str, mf.Email]

@dataclass
class ContactInfo:
    mail: Email

@dataclass
class Network:
    ipv4: Annotated[str, mf.String(validate=mv.Regexp(r'^([0-9]{1,3}\\.){3}[0-9]{1,3}$'))]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions