Skip to content

what about decorator?! #2

Description

@minhoryang

Mock

class Test:
  name = ""  # RULES: limitrange(10,20)

-> lib2to3.pgen2

Converted

from popo import String

class _Test_Mock:
  def __init__(self):
    String(self, "name", "", {"limitrange": ((10, 20), {})})

if __name__ == "__main__":
  Generate(_Test_Mock)

is equivalent to (and works as)

class _Test_Mock:
  def __init__(self):
    self._name = ""

  @property
  def name(self):
    return self._name

  @limitrange(10, 20)
  @name.setter
  def name(self, value):
     self._name = value

Usage:

class Test(_Test_Mock):
  def __init__(self, blah, blah):
    super.__init__(self)

for SQLAlchemy

What if replacing this

from popo import String, Generate

to

from popo.ext.sqlalchemy import String, Generate

Run it, then this will be generated.

class TestMixIn(object):
  name = db.Column(db.String(20))

Usage:

class Test(TestMixIn, db.Model):
  __tablename__ = "test"

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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