Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

I have a theory that it's impossible to prove anything, but I can't prove it.


devel / comp.lang.python / Re: Enum + new in 3.11

SubjectAuthor
o Re: Enum + new in 3.11Thomas Passin

1
Re: Enum + new in 3.11

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

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: lis...@tompassin.net (Thomas Passin)
Newsgroups: comp.lang.python
Subject: Re: Enum + new in 3.11
Date: Fri, 16 Jun 2023 07:47:42 -0400
Lines: 98
Message-ID: <mailman.108.1686916631.23016.python-list@python.org>
References: <3aaa63cd-2108-46d0-7fa5-295843703b1a@DancesWithMice.info>
<4d5f1ee0-4270-a232-1007-013dee43f794@tompassin.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de awTTa9w6bFF5gM7jo/E+CgT7cnakjxbDipHORiicg1Qw==
Return-Path: <list1@tompassin.net>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=tompassin.net header.i=@tompassin.net header.b=FFYLqe+r;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.012
X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'skip:@ 10': 0.03; 'url-
ip:140.82.114/24': 0.03; 'url-ip:140.82/16': 0.03; 'def': 0.04;
'"""': 0.09; 'recognised': 0.09; 'represents': 0.09; 'say:': 0.09;
'url:github': 0.14; 'import': 0.15; 'url-ip:140/8': 0.15;
'"there': 0.16; 'computation': 0.16; 'impossible': 0.16; 'indeed':
0.16; 'print(': 0.16; 'received:10.0.0': 0.16; 'received:64.90':
0.16; 'received:64.90.62': 0.16; 'received:64.90.62.162': 0.16;
'received:dreamhost.com': 0.16; 'says:': 0.16; 'wrote:': 0.16;
'python': 0.16; 'values': 0.17; 'to:addr:python-list': 0.20;
'section': 0.25; 'object': 0.26; 'function': 0.27; 'header:User-
Agent:1': 0.30; 'present': 0.30; 'am,': 0.31; 'python-list': 0.32;
'received:10.0': 0.32; 'received:mailchannels.net': 0.32;
'received:relay.mailchannels.net': 0.32; 'but': 0.32; 'there':
0.33; 'url:blog': 0.33; 'header:In-Reply-To:1': 0.34; 'following':
0.35; 'target': 0.36; 'member': 0.37; 'name:': 0.37; "skip:' 10":
0.37; 'class': 0.37; 'could': 0.38; 'read': 0.38; 'changes': 0.39;
'added': 0.39; 'least': 0.39; 'use': 0.39; '(see': 0.40; 'method':
0.61; 'skip:\xc2 10': 0.62; 'gain': 0.62; 'here': 0.62; 'skip:m
20': 0.63; 'imagine': 0.64; 'others,': 0.64; 'header:Received:6':
0.67; 'skip:e 20': 0.67; 'received:64': 0.67; 'order': 0.69;
'also:': 0.69; 'varying': 0.69; 'within': 0.69; '8bit%:100': 0.76;
'cautionary': 0.84; 'converted': 0.84; 'eventually': 0.84;
'idea....': 0.84; 'killed': 0.84; 'red,': 0.84; 'mixed': 0.93
X-Sender-Id: dreamhost|x-authsender|tpassin@tompassin.net
ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1686916064; a=rsa-sha256;
cv=none;
b=avfx3eMm/mfG3wnMeZdnzdRFFchkgUNC1F4G7oUIlr4dhPDLWUJMXjCPj3w1zP1LQuHpWp
/+wPFIYttdFpgUN2IDqgNNn/A0P29hftEj9lHwBnmjMhm7zum+uE/Vrb5E7/9zkR+LYZH4
AcaXo8pNKC4HLO3VlJcQ7uY5ZdeAwACZBglLKLIM5uREUktDCnADBOjDyMKq/Afyj/kKAT
rMQBwBEB+Z5bFF3mjAgbd9mjjsFwItlq/cAOjDf+jJeBWGvNNrSJ6NE/TrbwsG6hRgnLpB
L19Xf1i32yeMnLpc53r5g1fRggS2yhagk5t46GCrGtQUaReuZVAuBGE1M3G8dA==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed;
d=mailchannels.net; s=arc-2022; t=1686916064;
h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
to:to:cc:mime-version:mime-version:content-type:content-type:
content-transfer-encoding:content-transfer-encoding:
in-reply-to:in-reply-to:references:references:dkim-signature;
bh=EMD6uxYSPYxcJQ9x1YUsQ8H7d5NL65hOA3ng7031EAU=;
b=NXHljzEplvn9JgKRdJ/CI9Xu7PIqLmgTltP5OYFIhhAVc9yoUMR9W1zSgKNffdqpMBddLL
Af7Xsj7EnY9dMQ2fNLGCG6p1D1VqTun6A8UzIV44uK8N7F10TLyz/TFq7TF+Ly0hx8XjAT
roR3cfdBoN9E+sS1kQ+WQdTg6PmxOhryumnGAwnItSkaDFpIa8JR+xTr+41Yu1TYMuNcA4
vRqYIUv/kkiziwKdap08xeNtzbeE6V0N/hD189zl2q43UQRYNhnsMxOv4miMgRJLEOxiZ/
/aen+Bz77w5DmkrCanLVIA6uipuzmJ8g5zYW8b07v3aIzWfq92wj7iUVukw1lw==
ARC-Authentication-Results: i=1; rspamd-85899d6fcc-szbpm;
auth=pass smtp.auth=dreamhost smtp.mailfrom=list1@tompassin.net
X-Sender-Id: dreamhost|x-authsender|tpassin@tompassin.net
X-MC-Relay: Neutral
X-MailChannels-SenderId: dreamhost|x-authsender|tpassin@tompassin.net
X-MailChannels-Auth-Id: dreamhost
X-Irritate-Arch: 58f0570e511141c9_1686916064365_2140174409
X-MC-Loop-Signature: 1686916064365:3316793340
X-MC-Ingress-Time: 1686916064364
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tompassin.net;
s=dreamhost; t=1686916063;
bh=EMD6uxYSPYxcJQ9x1YUsQ8H7d5NL65hOA3ng7031EAU=;
h=Date:Subject:To:From:Content-Type:Content-Transfer-Encoding;
b=FFYLqe+r5a8EZmqBn+zEyu4oKhEMZwmtqwWnN//iz58gcAbxWWrE+GNtPQvSTFGh3
fS5ySOi6kNYLyxrXDCkdOBKmIUb0Xw8ow5uyNMGRiZs9BvzgrDnd6B0boWvUxgGHts
zwwn9cCRENpzbk+9Q1XHq0G50EtDPXMu3yJfOuwAMx1yg122OF41ncTo05mRinZNz/
Pgz8nplBO3m1ln/huCE5VD5abj6WRwVuj6/Ot7SX8OqMn06bJwzvm+GXl4A6Z9xqvK
iNb8/Z1cib9hCg0SDH4Dp9tI+2CUwPV01im6GUpS7CuC7V6Xz0mGf/y4Di/Yyqv1iF
TQfm4w6l+mevA==
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.12.0
Content-Language: en-US
In-Reply-To: <3aaa63cd-2108-46d0-7fa5-295843703b1a@DancesWithMice.info>
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.39
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: <4d5f1ee0-4270-a232-1007-013dee43f794@tompassin.net>
X-Mailman-Original-References: <3aaa63cd-2108-46d0-7fa5-295843703b1a@DancesWithMice.info>
 by: Thomas Passin - Fri, 16 Jun 2023 11:47 UTC

On 6/16/2023 1:40 AM, dn via Python-list wrote:
> Have you figured-out a use for the @enum.member and @enum.nonmember
> decorators (new in Python 3.11)?
>
>
> "What's New" says:
> Added the member() and nonmember() decorators, to ensure the decorated
> object is/is not converted to an enum member.
>
> The PSL docs say:
> @enum.member
>     A decorator for use in enums: its target will become a member.
>
> also:
> enum members have names and values (the name of Color.RED is RED, the
> value of Color.BLUE is 3, etc.)
>
> Whereas the "Utilities and Decorators" section is slightly confusing
> because class decorators are mixed with others, so one has to read
> more-carefully.
>
>
> "Curiosity killed the cat" and other cautionary tales/tails...
>
> Have added the following decorated staticmethod to a basic enum. It is
> indeed recognised as a member of the enum, but its value is the
> method-object. To gain the value the method-object represents
> (property-like behavior) one has to call the method/enum-value as a
> function:-
>
>
> from enum import Enum, member
>
>
> class MenuOptions( Enum ):
>     """ Legal menu-choices. """
>     N = "NewGame"
>     L = "LoadGame"
>     # ...
>
>     @member
>     @staticmethod
>     def extra_member()->str:
>         return "QuitGame"
>
>
> def print_demo( enum_chosen:MenuOptions )->None:
>     """ Illustrative printing. """
>     print( "Name:", enum_chosen, enum_chosen.name )
>     if isinstance( enum_chosen, MenuOptions ):
>         print( "Value:", enum_chosen.value )
>
>
> print( MenuOptions.__members__ )
> # {'N': <MenuOptions.N: 'NewGame'>, 'L': <MenuOptions.L: 'LoadGame'>,
> 'extra_member': <MenuOptions.extra_member: <staticmethod(<function
> MenuOptions.extra_member at 0x7f0802128860>)>>}
>
> print_demo( MenuOptions[ "L" ] )
> # Name: MenuOptions.L L
> # Value: LoadGame
>
> print_demo( MenuOptions.extra_member )
> # Name: MenuOptions.extra_member extra_member
> # Value: <staticmethod(<function MenuOptions.extra_member at
> 0x7f0802128860>)>
>
> print( MenuOptions.extra_member.value() )
> # QuitGame
>
>
> Therefore, like an @property decorator applied to a method in a
> custom-class, it could be used to only evaluate some 'expensive'
> computation if/when it is needed. Similarly, it could use the other
> values within the enum in order to present some 'combination'.
>
> Weirdly (given that enums are considered immutable) I imagine that if
> the 'extra_member' were to call some external function with varying
> output, the value could be considered mutable when it is eventually called.
>
> Other?better ideas...

mypy is having trouble with 3.11 enums:

"There are 83 open Enum mypy issues at the the time of this writing.

Getting the Enum datatype to work with mypy is becoming impossible as I
find myself having to use cast() in at least every other line."

(see https://github.com/python/mypy/issues/12841)

There have also been other changes to enum in 3.11 - here is a useful
rundown:

https://www.andy-pearce.com/blog/posts/2023/Jan/whats-new-in-python-311-new-and-improved-modules/#enum

I had no idea....

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor