Skip to content

Add @unique support to structure and field #68

Closed
@loyada

Description

@loyada
@unique
class Point(Structure):
     x: int
     y: int

Point(0,0)
Point(0, 0)
ValueError: Point instances must be unique
class Person(Structure):
     ssid: String(unique=True)
     name: str

Person(ssid="1234", name = "john")
Person(ssid="1234", name= "john")   # fine, because everything is the same, so refers to the same one
Person(ssid="1234", name = "Bob")
ValueError: ssid must be unique
@unique
class SSID(String): pass

class Woman(Structure):
     ssid: SSID
      name: str

class Man(Structure):
     ssid: SSID
      name: str

Man(ssid="1234", name = "john")
Wonan(ssid="1234", name = "sherry")
ValueError: ssid is unique

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions