Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

What the scientists have in their briefcases is terrifying. -- Nikita Khruschev


devel / comp.lang.python / Re: typing instance variable

SubjectAuthor
o Re: typing instance variableDennis Lee Bieber

1
Re: typing instance variable

<mailman.236.1621013588.3087.python-list@python.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=13147&group=comp.lang.python#13147

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: wlfr...@ix.netcom.com (Dennis Lee Bieber)
Newsgroups: comp.lang.python
Subject: Re: typing instance variable
Date: Fri, 14 May 2021 11:44:13 -0400
Organization: IISS Elusive Unicorn
Lines: 43
Message-ID: <mailman.236.1621013588.3087.python-list@python.org>
References: <20210514062848.GE14929@crfreenet.org>
<vi5t9gpg0qagtvnor32ck3a4ud71lmpplp@4ax.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de YtWTKSmQhkZAZt7lXma7iwkBQ523OsW50GKoFvYap+og==
Return-Path: <python-python-list@m.gmane-mx.org>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=none reason="no signature";
dkim-adsp=none (unprotected policy); dkim-atps=neutral
X-Spam-Status: OK 0.002
X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; '(most': 0.05; 'is.': 0.05;
'last):': 0.05; 'variable': 0.05; '"""': 0.09; 'int': 0.09;
'received:ciao.gmane.io': 0.09; 'received:gmane.io': 0.09;
'received:list': 0.09; 'url:reference': 0.09; 'url:stable': 0.09;
'+0200,': 0.16; 'accessed': 0.16; 'attributes': 0.16;
'attributes,': 0.16; 'declare': 0.16; 'declared': 0.16;
'defaults': 0.16; 'hides': 0.16; 'instance': 0.16; 'instances.':
0.16; 'message-id:@4ax.com': 0.16; 'received:116.202': 0.16;
'received:116.202.254': 0.16; 'received:116.202.254.214': 0.16;
'self.name': 0.16; 'subject:variable': 0.16; 'url:tutorial': 0.16;
'values': 0.16; 'python': 0.16; 'way.': 0.20; 'fri,': 0.23;
'to:addr:python-list': 0.23; 'anything': 0.24; 'default': 0.28;
'header:User-Agent:1': 0.31; 'header:Organization:1': 0.31;
'there': 0.31; 'but': 0.31; 'shared': 0.31; 'unexpected': 0.32;
'using': 0.33; 'class': 0.33; '100': 0.34; 'same': 0.34; 'url-
ip:104.17/16': 0.35; 'way': 0.37; 'file': 0.38; 'url-
ip:151.101.36.223/32': 0.38; 'url-ip:151.101.36/24': 0.38;
'comes': 0.40; 'initial': 0.61; 'upon': 0.63; 'body': 0.63;
'outside': 0.63; '8bit%:21': 0.64; 'experience': 0.64; 'lead':
0.67; 'url:8': 0.68; 'within': 0.68; 'accessible': 0.69;
'8bit%:38': 0.71; 'received:116': 0.71; 'skip:\xe2 10': 0.72;
'note:': 0.79; '2021': 0.84; 'attribute': 0.84; 'url-ip:76/8':
0.84; 'url:classes': 0.84; 'believes': 0.91; 'declaration': 0.91
X-Injected-Via-Gmane: http://gmane.org/
User-Agent: ForteAgent/8.00.32.1272
X-No-Archive: YES
X-Mailman-Approved-At: Fri, 14 May 2021 13:33:07 -0400
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.34
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: <https://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: <vi5t9gpg0qagtvnor32ck3a4ud71lmpplp@4ax.com>
X-Mailman-Original-References: <20210514062848.GE14929@crfreenet.org>
 by: Dennis Lee Bieber - Fri, 14 May 2021 15:44 UTC

On Fri, 14 May 2021 08:28:48 +0200, David Kolovratník
<david@kolovratnik.net> declaimed the following:

>
>python3 myclass.py
>Traceback (most recent call last):
> File "myclass.py", line 1, in <module>
> class MyClass:
>ValueError: 'foo' in __slots__ conflicts with class variable
>
>This is where the way of type declaration of instance variable comes from:
>
>https://mypy.readthedocs.io/en/stable/cheat_sheet_py3.html
>class MyClass:
> # You can optionally declare instance variables in the class body
> attr: int
> # This is an instance variable with a default value
> charge_percent: int = 100
>
>Why Python believes foo is class variable?
>

Based upon previous experience -- because it IS. Anything declared
outside of a method is a "class variable" which provides an initial value
to instance variable when used within a method.

https://docs.python.org/3.8/reference/compound_stmts.html#class-definitions
"""
Programmer’s note: Variables defined in the class definition are class
attributes; they are shared by instances. Instance attributes can be set in
a method with self.name = value. Both class and instance attributes are
accessible through the notation “self.name”, and an instance attribute
hides a class attribute with the same name when accessed in this way. Class
attributes can be used as defaults for instance attributes, but using
mutable values there can lead to unexpected results.
"""
https://docs.python.org/3.8/tutorial/classes.html#class-and-instance-variables

--
Wulfraed Dennis Lee Bieber AF6VN
wlfraed@ix.netcom.com http://wlfraed.microdiversity.freeddns.org/

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor