Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9166659
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:12:07+00:00 2026-06-17T15:12:07+00:00

As i mentioned in this previous post. Im trying to create a decorator which

  • 0

As i mentioned in this previous post. Im trying to create a decorator which does the following:

The decorated class represents a document in a Documentbased DB like CouchDB or MongoDB. The Decorator accepts on argument which is a instance of a connector to such a database. The Model Class (in this example User) does automatically map undefined attributes to fields in the DB.

Now i get stuck a bit :-/ The mentioned things is all working. But now i cant call any methods from the Model Class. I’m getting the following error.

TypeError: unbound method myfunc() must be called with User instance
as first argument (got nothing instead)

class Connector(object):
    def readvar(self, var):
        data = {"emailAddress":"jack.bauer@ctu.org", "lastName":"Bauer"}
        return data[var]

class DocumentDB(object):
    def __init__(self,connector):
        self.connector = connector

    def __call__(self, *args, **kargs):
        _c = self.connector

        class TransparentAttribute:         
            def __getattr__(self, attrname):
                try:
                    return _c.readvar(attrname)
                except:
                    return getattr(args[0], attrname)
        return TransparentAttribute

c = Connector()
@DocumentDB(c)
class User(object):

    username = "JackBauer"
    def doSomething(self):
        print "bla bla"
    def doSomethingElse(self):
        pass
    def myfunc(self):
        print "afadsadsf adsf asdf asdf"

u = User()
u.myfunc() # Does not work!!!
print u.emailAddress
print u.lastName
print u.username
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T15:12:09+00:00Added an answer on June 17, 2026 at 3:12 pm

    I’ve had a quick play, and it looks like subclassing the user works.

    class DocumentDB(object):
        def __init__(self,connector):
            self.connector = connector
    
        def __call__(self, user):
            _c = self.connector
    
            print self, user, _c # <__main__.DocumentDB object at 0x012DAD30> <class '__main__.User'> <__main__.Connector object at 0x012DAD70>
    
            class TransparentAttribute(user):
                def __getattr__(self, attrname):
                    try:
                        return _c.readvar(attrname)
                    except:
                        return getattr(user, attrname)
    
            return TransparentAttribute
    

    u = User()
    print type(u) # <class '__main__.TransparentAttribute'>
    u.myfunc() # afadsadsf adsf asdf asdf
    

    After u = User(), u is of type TransparentAttribute, and I think if you don’t subclass it then you basically replace your User instance with a TransparentAttribute instance (so all the User object’s local functions are gone).

    (But to be honest, some of this is a bit over my head – feel free to correct me)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was following a previous post on this that says: For LinkedList get is
In a previous post it was mentioned that an overload of the Select method
This is related to my previous post here . Running the actual script, I
This is a follow up to my previous AngularJS question . I am trying
I'm trying to use the example mentioned for using the previous api in Backbone's
This post is an offshoot of my previous post . However I have not
So, as mentioned in this answer and in the iOS 4.0 release notes ,
HI May i know how to make the scroll view as mentioned in this
somebody mentioned that the function (in this case a method) below is no good
In this question , I mentioned my assumption that rubyforge gems are more official,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.