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 3697116
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T04:49:16+00:00 2026-05-19T04:49:16+00:00

I tried to manipulate the __mro__ but it it read-only The use case is

  • 0

I tried to manipulate the __mro__ but it it read-only

The use case is as follow:

The Connection object created from pyodbc (a DBAPI) used to provide a property called ‘autocommit’. Lately I have wrapped a SQLAlchemy db connection pool around the pyodbc for better resource management. The new db pool will return a _ConnectionFairy, a connection proxy class, which no longer exposes the autocommit property.

I would very much want to leave the thrid party code alone. So inheritance of _ConnectionFairy is not really an option (I might need to override the Pool class to change how it creates a connection proxy. For source code, please see here)

A rather not-so elegant solution is to change all occurance of

conn.autocommit = True

to

# original connection object is accessible via .connection
conn.connection.autocommit = True 

So, I would like to know if it is possible at all to inject a set of getter, setter and property to an instance of _ConnectionFairy

  • 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-05-19T04:49:17+00:00Added an answer on May 19, 2026 at 4:49 am

    You can “extend” almost any class using following syntax:

    def new_func(self, param):
        print param
    
    class a:
        pass
    
    a.my_func = new_func
    b = a()
    b.my_func(10)
    

    UPDATE

    If you want to create some kind of wrappers for some methods you can use getattr and setattr to save original method and replace it with your implementation. I’ve done it in my project but in a bit different way:

    Here is an example:

    class A:
        def __init__(self):
            setattr(self, 'prepare_orig', getattr(self,'prepare'))
            setattr(self, 'prepare', getattr(self,'prepare_wrapper'))
    
        def prepare_wrapper(self,*args,**kwargs):
            def prepare_thread(*args,**kwargs):
                try:
                    self.prepare_orig(*args,**kwargs)
                except:
                    print "Unexpected error:", sys.exc_info()[0]
            t = threading.Thread(target=prepare_thread, args=args, kwargs=kwargs)
            t.start()
    
        def prepare(self):
            pass
    

    The idea of this code that other developer can just implement prepare method in derived classed and it will be executed in the background. It is not what you asked but I hope it will help you in some way.

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

Sidebar

Related Questions

I've tried to use java.net.URI to manipulate query strings but I failed to even
Tried to map it from Preferences -> Settings -> Keyboard, but the key combo
Tried examples from 'php.net' but don't understand what's the problem. Any suggestions? <?php $_SESSION['test']
Tried following the instructions here: How to use Google app engine with my own
Tried a bunch of things but I can't get it to work consistently amid
tried to find the answer by googling and in MSDN but with no luck.
Tried to install some program, it gives above message requiring 1.1.4322. BUT as the
tried to research on that but sometimes I seem to lack some googling skills...
I'd like to return the customers from Magento who where created the day before
I tried to manipulate an array in an NSMutableDictionary directly: [[myDictionary objectForKey: @key] addObject:

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.