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


Groups > comp.lang.python > #110960

Re: Namespaces are one honking great idea

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From Kevin Conway <kevinjacobconway@gmail.com>
Newsgroups comp.lang.python
Subject Re: Namespaces are one honking great idea
Date Sat, 02 Jul 2016 15:34:08 +0000
Lines 54
Message-ID <mailman.27.1467473666.2295.python-list@python.org> (permalink)
References <57767a97$0$1606$c3e8da3$5496439d@news.astraweb.com> <577693AC.6090807@stoneleaf.us> <mailman.2.1467388849.2295.python-list@python.org> <5776a3ef$0$1608$c3e8da3$5496439d@news.astraweb.com> <5776C4A4.5000407@stoneleaf.us> <mailman.5.1467401379.2295.python-list@python.org> <577713c6$0$1587$c3e8da3$5496439d@news.astraweb.com> <CAKF=+diE82nJ6wgN2oWYeysLytNqPnfEwngV7QsxwJVaHf1Ebg@mail.gmail.com> <1467435593.1705568.654776673.4D901A33@webmail.messagingengine.com> <CAKF=+dhApO5w_wzXgnUwzr+V5-NXOLas_Mjf3Yr7jm9VSoFfzA@mail.gmail.com>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8
X-Trace news.uni-berlin.de xCxjTsz3KwhMT5Vndrj/MA8M5fppi9u7veI305fMKiHg==
Return-Path <kevinjacobconway@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.020
X-Spam-Evidence '*H*': 0.96; '*S*': 0.00; 'static': 0.03; '"class"': 0.09; 'instances.': 0.09; 'namespace': 0.09; 'def': 0.13; 'appropriate': 0.14; 'variables': 0.15; '(well,': 0.16; '*should*': 0.16; '@classmethod': 0.16; 'magic': 0.16; 'namespace,': 0.16; 'namespace.': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'subject:Namespaces': 0.16; 'wrote:': 0.16; '&gt;': 0.18; 'language': 0.19; 'proposed': 0.20; 'to:2**1': 0.21; 'referring': 0.22; 'defined': 0.23; '(or': 0.23; 'kevin': 0.23; 'sat,': 0.23; 'header:In-Reply-To:1': 0.24; 'example': 0.26; 'fri,': 0.27; 'message-id:@mail.gmail.com': 0.27; 'classes': 0.30; 'url:mailman': 0.30; 'creating': 0.30; 'code': 0.30; 'class.': 0.30; 'class': 0.33; 'url:python': 0.33; 'instances': 0.33; 'point,': 0.33; 'url:listinfo': 0.34; 'received:google.com': 0.35; 'skip:c 30': 0.35; 'instance': 0.35; "isn't": 0.35; 'url:org': 0.36; 'cases': 0.36; 'modules': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'skip:& 10': 0.37; 'method': 0.37; 'seem': 0.37; 'no,': 0.38; 'skip:p 20': 0.38; 'url:mail': 0.40; 'to:addr:python.org': 0.40; 'called': 0.40; 'term': 0.60; 'provide': 0.61; 'more': 0.63; 'within': 0.64; 'believe': 0.66; 'skip:\xc2 10': 0.67; '8bit%:100': 0.70; 'covers': 0.72; 'jul': 0.72; 'directly.': 0.76; 'satisfied': 0.83; 'change?': 0.84; 'decorators.': 0.84; 'carries': 0.91; 'technically': 0.91
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=R7oWYDgS2OmGuaX0oSQujBTjsNnK1ObjbHZM5icgttk=; b=J5H8y6Im+m1wnpie4xZoup054+ztbKiynMnL0UBqMffPekVUszH8sDiWD63gqcZHpq keyCG4f5m3W5xkSof0EbfQjZFw2A84pf/2gfDKlS2i1JaTX3SzTzwUu+vjGeWBn3xwfB Oab/Pw+f9d6kfY6AABN/rNF31ACC2RTRDZGEXBs0GC//PBNClkQo5KmNIUIU8Wjhj+E7 kEvY8Qc2RF2zQaJCrUvTiEXMLsj3O6oyinuJkBkzVhJ+V1Uc+YciV5ORN/GZRsc55mRw 4aCpSjcNGpuWbBKih0lmZoNH/OZ0vBwYIsMnmf+IQu84byBeT4ZA8f1Djzu22NIk8dvB KPYA==
X-Google-DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=R7oWYDgS2OmGuaX0oSQujBTjsNnK1ObjbHZM5icgttk=; b=Bgaqc4S/SqAdUL6TkY2sZXvymRDYd0tdPoBOQLDP7YQaLTUABUnR79L20g4pf2MtK4 njC+ZTVkqJjcfB3HlfaRJXWqeP39dZEpis6UAhd8Ieav/1QIBh5b0s/yNCRWl2SQ9at4 smln3pwhd5ZrDYUxfUol3e7XuOOXxDobNyWogl+PGhMDR/NMN+Bh+OTJUlXy05ckrOEH CYdK3YXr87DOyOZ0iu/NQeQOtE3GuVMDcXpO27r8O+qHQrZV77/H2E59KftHNdHeb7RA E1FbtHh2VY678NFpQokZodnhdW1jZK1UKqU8ohQmzRKZAZp7RofVtlSk9pidC6eR3o76 paig==
X-Gm-Message-State ALyK8tK08WTsXH/CBRCPZcpBLuGPPjAbtBKRyxY6dQdV4C1DlhbbX+0lfbvOPgk1UUmi6i3+cyyb0c2qUSL4yw==
X-Received by 10.176.5.161 with SMTP id e30mr156211uae.92.1467473657607; Sat, 02 Jul 2016 08:34:17 -0700 (PDT)
In-Reply-To <1467435593.1705568.654776673.4D901A33@webmail.messagingengine.com>
X-Content-Filtered-By Mailman/MimeDel 2.1.22
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.22
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID <CAKF=+dhApO5w_wzXgnUwzr+V5-NXOLas_Mjf3Yr7jm9VSoFfzA@mail.gmail.com>
X-Mailman-Original-References <57767a97$0$1606$c3e8da3$5496439d@news.astraweb.com> <577693AC.6090807@stoneleaf.us> <mailman.2.1467388849.2295.python-list@python.org> <5776a3ef$0$1608$c3e8da3$5496439d@news.astraweb.com> <5776C4A4.5000407@stoneleaf.us> <mailman.5.1467401379.2295.python-list@python.org> <577713c6$0$1587$c3e8da3$5496439d@news.astraweb.com> <CAKF=+diE82nJ6wgN2oWYeysLytNqPnfEwngV7QsxwJVaHf1Ebg@mail.gmail.com> <1467435593.1705568.654776673.4D901A33@webmail.messagingengine.com>
Xref csiph.com comp.lang.python:110960

Show key headers only | View raw


> staticmethod isn't technically required to use a method through the class
(or subclasses), it simply provides the appropriate magic to allow it to be
called through instances.

For example, the following code covers all described use cases of the
proposed namespace. Methods are invoked without creating instances and
state is managed on the class object directly.

class CustomNs:

    stateful_data = 1

    @staticmethod
    def echo(text):
        print(text)

    @classmethod
    def mutate(cls):
        cls.stateful_data += 1
        print(cls.stateful_data)

CustomNs.echo("test")
print(CustomNs.stateful_data)
CustomNs.mutate()
print(CustomNs.stateful_data)

For the proponents of namespace, what is deficient in the above example
that necessitates a language change?

On Sat, Jul 2, 2016, 00:02 Random832 <random832@fastmail.com> wrote:

> On Fri, Jul 1, 2016, at 21:50, Kevin Conway wrote:
> > I believe the namespace object you are referring to is exactly a
> > class. IIRC, classes came about as a "module in a module".
>
> No, because classes have instances. And conceptually they seem like they
> *should* have instances. Just using the term "class" carries
> expectations.
>
> More to the point, what modules do that classes do not is provide a
> global namespace for functions defined within them, so that variables
> within them can be used (well, read - writing them requires a
> declaration) by the functions without extra qualification.
>
> > Regardless, all use cases you've listed are already satisfied by use
> > of the static and class method decorators. Methods decorated with
> > these do not require an instance initialization to use.
>
> staticmethod isn't technically required to use a method through the
> class (or subclasses), it simply provides the appropriate magic to allow
> it to be called through instances.
> --
> https://mail.python.org/mailman/listinfo/python-list
>

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


Thread

Namespaces are one honking great idea Steven D'Aprano <steve@pearwood.info> - 2016-07-02 00:13 +1000
  Re: Namespaces are one honking great idea Random832 <random832@fastmail.com> - 2016-07-01 10:40 -0400
  Re: Namespaces are one honking great idea BartC <bc@freeuk.com> - 2016-07-01 15:49 +0100
    Re: Namespaces are one honking great idea Chris Angelico <rosuav@gmail.com> - 2016-07-02 03:13 +1000
    Re: Namespaces are one honking great idea Steven D'Aprano <steve@pearwood.info> - 2016-07-02 03:46 +1000
    Re: Namespaces are one honking great idea Rustom Mody <rustompmody@gmail.com> - 2016-07-01 19:26 -0700
  Re: Namespaces are one honking great idea Ethan Furman <ethan@stoneleaf.us> - 2016-07-01 09:00 -0700
    Re: Namespaces are one honking great idea Steven D'Aprano <steve@pearwood.info> - 2016-07-02 03:10 +1000
      Re: Namespaces are one honking great idea Ethan Furman <ethan@stoneleaf.us> - 2016-07-01 12:29 -0700
        Re: Namespaces are one honking great idea Steven D'Aprano <steve@pearwood.info> - 2016-07-02 11:07 +1000
          Re: Namespaces are one honking great idea Kevin Conway <kevinjacobconway@gmail.com> - 2016-07-02 01:50 +0000
            Re: Namespaces are one honking great idea Lawrence D’Oliveiro <lawrencedo99@gmail.com> - 2016-07-01 19:55 -0700
            Re: Namespaces are one honking great idea Steven D'Aprano <steve@pearwood.info> - 2016-07-03 13:22 +1000
          Re: Namespaces are one honking great idea Random832 <random832@fastmail.com> - 2016-07-02 00:59 -0400
          Re: Namespaces are one honking great idea Kevin Conway <kevinjacobconway@gmail.com> - 2016-07-02 15:34 +0000
            Re: Namespaces are one honking great idea Steven D'Aprano <steve@pearwood.info> - 2016-07-03 13:44 +1000
              Re: Namespaces are one honking great idea Ethan Furman <ethan@stoneleaf.us> - 2016-07-02 22:14 -0700
              Re: Namespaces are one honking great idea Kevin Conway <kevinjacobconway@gmail.com> - 2016-07-03 22:02 +0000
                Re: Namespaces are one honking great idea Lawrence D’Oliveiro <lawrencedo99@gmail.com> - 2016-07-03 16:21 -0700
                Re: Namespaces are one honking great idea BartC <bc@freeuk.com> - 2016-07-04 01:19 +0100
              Re: Namespaces are one honking great idea Ethan Furman <ethan@stoneleaf.us> - 2016-07-03 21:01 -0700
          Re: Namespaces are one honking great idea Ethan Furman <ethan@stoneleaf.us> - 2016-07-02 16:28 -0700
  Re: Namespaces are one honking great idea Chris Angelico <rosuav@gmail.com> - 2016-07-04 21:37 +1000
    Re: Namespaces are one honking great idea Lawrence D’Oliveiro <lawrencedo99@gmail.com> - 2016-07-04 15:09 -0700
      Re: Namespaces are one honking great idea Lawrence D’Oliveiro <lawrencedo99@gmail.com> - 2016-07-04 15:11 -0700
  Re: Namespaces are one honking great idea jmp <jeanmichel@sequans.com> - 2016-07-04 17:58 +0200
  Re: Namespaces are one honking great idea Chris Angelico <rosuav@gmail.com> - 2016-07-05 12:58 +1000
    Re: Namespaces are one honking great idea Steven D'Aprano <steve@pearwood.info> - 2016-07-05 13:35 +1000
      Re: Namespaces are one honking great idea Chris Angelico <rosuav@gmail.com> - 2016-07-05 13:47 +1000
        Re: Namespaces are one honking great idea Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2016-07-05 16:09 +1000
          A nestedmodule decorator (Re: Namespaces are one honking great idea) Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2016-07-05 21:10 +1200
            Improved nestedmodule decorator implementation Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2016-07-05 21:31 +1200
              Re: Improved nestedmodule decorator implementation Steven D'Aprano <steve@pearwood.info> - 2016-07-05 20:54 +1000
  Re: Namespaces are one honking great idea Steven D'Aprano <steve@pearwood.info> - 2016-07-05 12:34 +1000
  Re: Namespaces are one honking great idea jmp <jeanmichel@sequans.com> - 2016-07-04 13:23 +0200
  Re: Namespaces are one honking great idea carlosjosepita@gmail.com - 2016-07-09 07:05 -0700

csiph-web