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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T05:07:32+00:00 2026-05-14T05:07:32+00:00

I would like to control which methods appear when a user uses tab-completion on

  • 0

I would like to control which methods appear when a user uses tab-completion on a custom object in ipython – in particular, I want to hide functions that I have deprecated. I still want these methods to be callable, but I don’t want users to see them and start using them if they are inspecting the object. Is this something that is possible?

  • 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-14T05:07:32+00:00Added an answer on May 14, 2026 at 5:07 am

    Partial answer for you. I’ll post the example code and then explain why its only a partial answer.
    Code:

    class hidden(object): # or whatever its parent class is
        def __init__(self):
            self.value = 4
        def show(self):
            return self.value
        def change(self,n):
            self.value = n
        def __getattr__(self, attrname):
            # put the dep'd method/attribute names here
            deprecateds = ['dep_show','dep_change']
            if attrname in deprecateds:
                print("These aren't the methods you're looking for.")
                def dep_change(n):
                    self.value = n
                def dep_show():
                    return self.value
                return eval(attrname)
            else:
                raise AttributeError, attrname
    

    So now the caveat: they’re not methods (note the lack of self as the first variable). If you need your users (or your code) to be able to call im_class, im_func, or im_self on any of your deprecated methods, then this hack won’t work. Also, i’m pretty sure there’s going to be a performance hit because you’re defining each dep’d function inside __getattr__. This won’t affect your other attribute lookups (had I put them in __getattribute__, that would be a different matter), but it will slow down access to those deprecated methods. This can be (largely, but not entirely) negated by putting each function definition inside its own if block, instead of doing a list-membership check, but, depending on how big your function is, that could be really annoying to maintain.

    UPDATE:

    1) If you want to make the deprecated functions methods (and you do), just use

    import types
    return types.MethodType(eval(attrname), self)
    

    instead of

    return eval(attrname)

    in the above snippet, and add self as the first argument to the function defs. It turns them into instancemethods (so you can use im_class, im_func, and im_self to your heart’s content).

    2) If the __getattr__ hook didn’t thrill you, there’s another option (that I know of) (albiet, with its own caveats, and we’ll get to those): Put the deprecated functions definitions inside __init__, and hide them with a custom __dir__. Here’s what the above code would look like done this way:

    class hidden(object):
        def __init__(self):
            self.value = 4
            from types import MethodType
            def dep_show(self):
                return self.value
            self.__setattr__('dep_show', MethodType(dep_show, self))
            def dep_change(self, n):
                self.value = n
            self.__setattr__('dep_change', MethodType(dep_change, self))
        def show(self):
            return self.value
        def change(self, n):
            self.value = n
        def __dir__(self):
            heritage = dir(super(self.__class__, self)) # inherited attributes
            hide = ['dep_show', 'dep_change']
            show = [k for k in self.__class__.__dict__.keys() + self.__dict__.keys() if not k in heritage + private]
            return sorted(heritage + show)
    

    The advantage here is that you’re not defining the functions anew every lookup, which nets you speed. The disadvantage here is that because you’re not defining functions anew each lookup, they have to ‘persist’ (if you will). So, while the custom __dir__ method hides your deprecateds from dir(hiddenObj) and, therefore, IPython’s tab-completion, they still exist in the instance’s __dict__ attribute, where users can discover them.

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

Sidebar

Ask A Question

Stats

  • Questions 396k
  • Answers 396k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer OK, after doing a little digging around it turned out… May 15, 2026 at 3:03 am
  • Editorial Team
    Editorial Team added an answer Edit the column, edit the DefaultCellStyle property and set the… May 15, 2026 at 3:03 am
  • Editorial Team
    Editorial Team added an answer You could use the "class" of each option to hold… May 15, 2026 at 3:03 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.