Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Peter Otten <__peter__@web.de> Newsgroups: comp.lang.python Subject: Re: Clean Singleton Docstrings Date: Fri, 08 Jul 2016 09:38:29 +0200 Organization: None Lines: 63 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit X-Trace: news.uni-berlin.de p65svG5Jx+V36+MUvr5MLgpTBGXomDsSzY6LQDOevg4g== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'none:': 0.05; 'though:': 0.07; 'collections': 0.09; 'complicate': 0.09; 'dict': 0.09; 'expected.': 0.09; 'mutable': 0.09; 'object;': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'bug': 0.10; 'python': 0.10; "%r'": 0.16; 'boolean': 0.16; 'commensurate': 0.16; 'evaluates': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; 'received:t-ipconnect.de': 0.16; 'registry': 0.16; 'subject:Singleton': 0.16; 'userdict': 0.16; 'wrote:': 0.16; 'import': 0.24; "i've": 0.25; 'header:User-Agent:1': 0.26; 'command': 0.26; 'header:X-Complaints-To:1': 0.26; 'skip:_ 20': 0.26; 'module.': 0.27; "skip:' 10": 0.28; 'device': 0.28; 'resolution': 0.28; 'cat': 0.29; 'context,': 0.29; 'raise': 0.29; 'allows': 0.30; "we're": 0.30; 'putting': 0.30; 'fixed': 0.31; 'class': 0.33; 'skip:_ 30': 0.33; 'accessible': 0.33; 'environment,': 0.33; 'file': 0.34; 'gives': 0.35; 'skip:c 30': 0.35; 'replace': 0.35; 'something': 0.35; 'asking': 0.35; 'there': 0.36; '(i.e.': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'method': 0.37; 'received:org': 0.37; 'things': 0.38; 'test': 0.39; 'application': 0.39; 'to:addr:python.org': 0.40; 'received:de': 0.40; 'your': 0.60; 'share': 0.61; 'information': 0.63; 'within': 0.64; 'you.': 0.64; 'state.': 0.72; 'console,': 0.84; 'object:': 0.84; 'order:': 0.84 X-Injected-Via-Gmane: http://gmane.org/ X-Gmane-NNTP-Posting-Host: p57bd939c.dip0.t-ipconnect.de User-Agent: KNode/4.13.3 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Mailman-Original-Message-ID: X-Mailman-Original-References: Xref: csiph.com comp.lang.python:111202 Rob Gaddi wrote: > I've got a package that contains a global ensmartened dict that allows > all the various parts of my program to share state. Things like device > handles, information about the application environment, etc. that are > inherantly global (i.e. we're not having that debate). > > Implementation is: > > class _Registry(UserDict): > """Docstring!""" > ... > Registry = _Registry() > > So Registry is now a globally accessible mutable object; no reason to > complicate things with singletons or borgs or whathave you. From > within the interactive console, help(foobar.Registry) gives me the > _Registry documentation as expected. > > From the (Linux) command line though: > $ pydoc3 foobar._Registry > [lots of good documentation stuff] > $ pydoc3 foobar.Registry > no Python documentation found for 'foobar.Registry' > > Is this a thing that can be fixed with a commensurate amount of effort? There is a test if not object: raise ImportError('no Python documentation found for %r' % thing) in the pydoc module. So all you need is to ensure that your Registry evaluates to True in a boolean context, e. g. by putting something into it: $ cat foobar.py from collections import UserDict class _Registry(UserDict): """Docstring!""" Registry = _Registry() Registry["dummy"] = 42 $ pydoc3 foobar.Registry | head -n 10 Help on _Registry in foobar object: foobar.Registry = class _Registry(collections.UserDict) | Docstring! | | Method resolution order: | _Registry | collections.UserDict | collections.abc.MutableMapping | collections.abc.Mapping You might also file a bug report asking to replace if not object: ... with if object is None: ...