View Issue Details

IDProjectCategoryView StatusLast Update
0004186CaseTalk ModelerGeneration (SQL, XML, etc)public2023-10-05 14:09
ReporterBCP Software Assigned ToBCP Software  
PrioritynormalSeveritytweakReproducibilityhave not tried
Status resolvedResolutionfixed 
PlatformIntelOSWindowsOS Version11
Target Version13.0.1Fixed in Version13.0.1 
Summary0004186: Python metadata class
DescriptionThe dataclass provides an easy way to generate bootstrap functions for code use. Yet, the metadata annotated in CaseTalk has no proper way of entering, except through metadata definitions.

See: https://workshop-python.readthedocs.io/advanced/dataclass/metadata.html
Additional Information
@dataclass
class User:
    firstname: str
    lastname: str
    age: int = field(default=None, metadata={'min': 27, 'max': 50})

    def __post_init__(self):
        AGE_MIN = self.__dataclass_fields__['age'].metadata['min']
        AGE_MAX = self.__dataclass_fields__['age'].metadata['max']

        if self.age not in range(AGE_MIN, AGE_MAX):
            raise ValueError('Invalid age')
TagsNo tags attached.
CaseTalk Editionunknown

Activities

BCP Software

BCP Software

2023-10-05 13:40

administrator   ~0004968

Last edited: 2023-10-05 14:03

The CaseTalkBaseClass is added with metadata support for constraints:

#
# Base class to support checking constraints through metadata.
#
@dataclass
class CaseTalkBaseClass:
  def __post_init__(self):
    for fieldname, field in self.__dataclass_fields__.items():
      if 'required' in field.metadata:
        if field.metadata['required'] == True and getattr(self, fieldname) is none:
          raise ValueError('{fieldname} is Required')
  def __eq__(self, other):
    result = None
    for fieldname, field in self.__dataclass_fields__.items():
      if 'id' in field.metadata:
        if field.metadata['id'] == True:
          result = cmp(getattr(self, fieldname), getattr(other, fieldname))
          if result <> 0:
            break
    return result

@dataclass
class Student(CaseTalkBaseClass):
  firstname: str = field(metadata={'required'=True, 'id'=True})
  lastname: str = field(metadata={'required'=True, 'id'=True})
  buddy: Student
  type: Type = field(default="Student")

Issue History

Date Modified Username Field Change
2023-10-05 12:14 BCP Software New Issue
2023-10-05 12:14 BCP Software Status new => assigned
2023-10-05 12:14 BCP Software Assigned To => BCP Software
2023-10-05 13:40 BCP Software Note Added: 0004968
2023-10-05 13:41 BCP Software Note Edited: 0004968
2023-10-05 14:02 BCP Software Note Edited: 0004968
2023-10-05 14:03 BCP Software Note Edited: 0004968
2023-10-05 14:09 BCP Software Status assigned => resolved
2023-10-05 14:09 BCP Software Resolution open => fixed
2023-10-05 14:09 BCP Software Fixed in Version => 13.0.1