Skip to content

Conversation

@Kircheneer
Copy link
Contributor

This is a draft of an attempt to simplify the interface for defining models a bit. Here is what an example model definition now might look like:

from typing import Annotated, List. Optional

from diffsync.enum import DiffSyncFieldtype
from diffsync import DIffSyncModel


class City(DiffSyncModel):
    _modelname = "city"

    name: Annotated[str, DiffSyncFieldType.IDENTIFIER]
    population: Annotated[int, DiffSyncFieldType.ATTRIBUTE]


class Country(DebugModel):
    _modelname = "country"

    name: Annotated[str, DiffSyncFieldType.IDENTIFIER]
    iso_code: Annotated[Optional[str], DiffSyncFieldType.ATTRIBUTE]
    cities: Annotated[List[City], DiffSyncFieldType.CHILDREN, "city"] = []

Open points

  • Evaluate, whether this breaking change (eyeing at 2.0) is worth it
  • Documentation
  • Think about further possibilites for simplification

@Kircheneer Kircheneer force-pushed the simplify-model-interface branch from ee108b6 to 52cd49b Compare June 20, 2023 15:06
@Kircheneer Kircheneer mentioned this pull request Jun 20, 2023
7 tasks
@Kircheneer Kircheneer force-pushed the simplify-model-interface branch from 52cd49b to 723f88f Compare June 20, 2023 15:20
@itdependsnetworks
Copy link
Contributor

I thought that this was only available in 3.9 and above? https://docs.python.org/3/library/typing.html#typing.Annotated

@Kircheneer
Copy link
Contributor Author

I thought that this was only available in 3.9 and above? https://docs.python.org/3/library/typing.html#typing.Annotated

True actually, I didn't know. Should use this for compatibility

@Kircheneer
Copy link
Contributor Author

Closing for now.

@Kircheneer Kircheneer closed this Feb 15, 2024
@jdrew82 jdrew82 deleted the simplify-model-interface branch March 27, 2025 22:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants