Skip to content
This repository was archived by the owner on Aug 27, 2023. It is now read-only.
This repository was archived by the owner on Aug 27, 2023. It is now read-only.

Causes conflict with properties #31

@justinoue

Description

@justinoue

When using new style class properties, inheriting Model causes a conflict.

I assume this is because all non "_" prefixed class attributes are expected to be Fields.

For example:

from flywheel import Model, Field
class Breakfast(Model):
  meal_id = Field(hash_key=True, data_type=int)
  @property
  def eggs(self):
    return self._eggs

  @eggs.setter
  def eggs(self, value):
    self._eggs = value

  @eggs.deleter
  def eggs(self):
    del self._eggs

  def __init__(self):
    self._eggs = None
    if not self.eggs:
      self.eggs = 'scrambled'


if __name__ == '__main__':
  t = Breakfast()
  print(t.eggs)

This prints None

vs

class Breakfast():
  @property
  def eggs(self):
    return self._eggs

  @eggs.setter
  def eggs(self, value):
    self._eggs = value

  @eggs.deleter
  def eggs(self):
    del self._eggs

  def __init__(self):
    self._eggs = None
    if not self.eggs:
      self.eggs = 'scrambled'


if __name__ == '__main__':
  t = Breakfast()
  print(t.eggs)

this properly prints "scrambled".

I think I can overcome what I intended to do with properties by using custom data types. I just wanted to bring this up.

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