Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #92510

Get classes from "self.MyClass" to improve subclassability

Newsgroups comp.lang.python
Date 2015-06-12 04:12 -0700
Message-ID <4d336971-d986-4e21-85a2-ddc8ee995c7e@googlegroups.com> (permalink)
Subject Get classes from "self.MyClass" to improve subclassability
From Thomas Güttler <hv@tbz-pariv.de>

Show all headers | View raw


Here is a snippet from the argparse module:

{{{
    def parse_known_args(self, args=None, namespace=None):
        ...
        # default Namespace built from parser defaults
        if namespace is None:
            namespace = Namespace() # < ======= my issue
}}}

I subclass from the class of the above snippet.

I would like to use a different Namespace class.

if the above could would use

    namespace = self.Namespace()

it would be very easy for me to inject a different Namespace class.

Yes, I have seen the "namespace" kwarg.

This is not the first time I would like the upstream code to make subclassing more fun.

Some months ago I asked myself how to call the "self.Namespace()" pattern:
 
http://stackoverflow.com/questions/27571848/name-of-design-pattern-get-class-from-class-level

The answer with the most upvotes states it is the Factory method pattern.

I prefer "self.Namespace()" to namespace kwargs.

What do you think? 

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Get classes from "self.MyClass" to improve subclassability Thomas Güttler <hv@tbz-pariv.de> - 2015-06-12 04:12 -0700
  Re: Get classes from "self.MyClass" to improve subclassability Chris Angelico <rosuav@gmail.com> - 2015-06-12 21:28 +1000
  Re: Get classes from "self.MyClass" to improve subclassability Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-06-12 12:23 +0000
    Re: Get classes from "self.MyClass" to improve subclassability Thomas Güttler <hv@tbz-pariv.de> - 2015-06-12 05:47 -0700
  Re: Get classes from "self.MyClass" to improve subclassability Terry Reedy <tjreedy@udel.edu> - 2015-06-12 19:08 -0400
    Re: Get classes from "self.MyClass" to improve subclassability Thomas Güttler <hv@tbz-pariv.de> - 2015-06-15 06:14 -0700

csiph-web