Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

The first version always gets thrown away.


devel / comp.lang.python / Re: Match statement with literal strings

SubjectAuthor
* Match statement with literal stringsJason Friedman
`* Re: Match statement with literal stringsGreg Ewing
 `- Re: Match statement with literal stringsJason Friedman

1
Match statement with literal strings

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

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!usenet.goja.nl.eu.org!3.eu.feeder.erje.net!feeder.erje.net!fu-berlin.de!uni-berlin.de!not-for-mail
From: jsf80...@gmail.com (Jason Friedman)
Newsgroups: comp.lang.python
Subject: Match statement with literal strings
Date: Wed, 7 Jun 2023 16:18:14 -0600
Lines: 33
Message-ID: <mailman.64.1686176306.23016.python-list@python.org>
References: <CANy1k1i9bq-=gTHxo7m_qW_zXJqbxFs9vLBs7q=WKRUhxozJ_g@mail.gmail.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
X-Trace: news.uni-berlin.de JMH68h5g/HIaEYCbn1/ppgH9d4zUoP3/NkclHBjI4HYg==
Return-Path: <jsf80238@gmail.com>
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=gmail.com header.i=@gmail.com header.b=qBPqS7a9;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.063
X-Spam-Evidence: '*H*': 0.89; '*S*': 0.02; 'this:': 0.03; 'row': 0.05;
'mandatory': 0.16; 'patterns': 0.16; 'syntaxerror:': 0.16;
'to:addr:python-list': 0.20; '(and': 0.25; 'message-
id:@mail.gmail.com': 0.32; 'received:google.com': 0.34;
'from:addr:gmail.com': 0.35; 'match': 0.40; 'skip:o 10': 0.61;
'gives': 0.62; 'range': 0.64; 'remaining': 0.69; 'capture': 0.84
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20221208; t=1686176305; x=1688768305;
h=to:subject:message-id:date:from:mime-version:from:to:cc:subject
:date:message-id:reply-to;
bh=n8NuChkjQ5tJZdO5pLlkDEKCNAu99TgR4abodfqZmhI=;
b=qBPqS7a9CT5gbRkYlPJoCzaShu/HS8oV6BpeiJKgj7ORhpeq4i45gEC7Hlex3kvMl5
h7jykFjnHIzDp60ZO4UNt+pySQoluu98C2klOxEn5VVt+XdOf9xeWTbn4G0gpvlrz/D4
cUYwOdoFRXymOE+Mnq742XcyWANeHpCwbcRB7Gba4OC9SQHzKShmF6PQj/8ErG8PRW67
ydSQ4Tp1tZKZm4hiQndE40BVRL0Susfa0qxaOzLS57U3kcAu1zn5zgHjbXeFcewNhYEI
Lxbk0tGJ5i083ifwxUw9CCCQH2qDdkTw26jsZ9cjggJhMOx93DEhRMe7bwaIhrihAYq2
WlsA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20221208; t=1686176305; x=1688768305;
h=to:subject:message-id:date:from:mime-version:x-gm-message-state
:from:to:cc:subject:date:message-id:reply-to;
bh=n8NuChkjQ5tJZdO5pLlkDEKCNAu99TgR4abodfqZmhI=;
b=YN7nQ8CBIQy7ywNhCqYa6h+gPUrUiw8T0QiqfMqfpVQDbkTv2RwZ7TfnSBSN/hHmsL
/MunguL7TM4igLhgOGiCIZM4Dn5ZE26H5DFWtyNlKVdsDLHXWwiL/Kfy6HcvPudq9rym
izfiKnuBjua1uBV9roYQDWHS3Dk0IIXDzjB5aPdCzyxMlA7DpyuwEPBKijFCX/YQFVUL
nU3n17NufnCeNA1EzUg9lYMXaXLnQBP01ii9fPdlCwdjnOKoDr/RVQDXsjWrel8Eu79N
QPDH/3fJfqaG5xXaZTgnuglRbOS8VLdFerdaZ7JpgLXnjDRZjEsQ3AgKVQ4eX+dolmpV
Gn2w==
X-Gm-Message-State: AC+VfDxZ76BF8lHar5fkiKS703TY/6/UKHWI64afTBvpOKtedB6jVAHD
e96L/DQK7uSvtzsf1vjCf8bb27sFw7JQ5SFJ58G+dH+MkCI=
X-Google-Smtp-Source: ACHHUZ6PNjnatd5R98xp6p4NSwh//06Wdw+4Dp0hlPtGHXLY/gKrcEq0GbjRbt7lndRhwdW+VtBSEjzYrNxiMLyTvSU=
X-Received: by 2002:aa7:d308:0:b0:514:7a67:44dc with SMTP id
p8-20020aa7d308000000b005147a6744dcmr5253883edq.19.1686176305226; Wed, 07 Jun
2023 15:18:25 -0700 (PDT)
X-Content-Filtered-By: Mailman/MimeDel 2.1.39
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: <CANy1k1i9bq-=gTHxo7m_qW_zXJqbxFs9vLBs7q=WKRUhxozJ_g@mail.gmail.com>
 by: Jason Friedman - Wed, 7 Jun 2023 22:18 UTC

This gives the expected results:

with open(data_file, newline="") as reader:
csvreader = csv.DictReader(reader)
for row in csvreader:
#print(row)
match row[RULE_TYPE]:
case "RANGE":
print("range")
case "MANDATORY":
print("mandatory")
case _:
print("nothing to do")

This:

RANGE = "RANGE"
MANDATORY = "MANDATORY"
with open(data_file, newline="") as reader:
csvreader = csv.DictReader(reader)
for row in csvreader:
#print(row)
match row[RULE_TYPE]:
case RANGE:
print("range")
case MANDATORY:
print("mandatory")
case _:
print("nothing to do")

Gives (and I don't understand why):

SyntaxError: name capture 'RANGE' makes remaining patterns unreachable

Re: Match statement with literal strings

<kecjtuFnbj5U1@mid.individual.net>

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: greg.ew...@canterbury.ac.nz (Greg Ewing)
Newsgroups: comp.lang.python
Subject: Re: Match statement with literal strings
Date: Thu, 8 Jun 2023 11:58:51 +1200
Lines: 25
Message-ID: <kecjtuFnbj5U1@mid.individual.net>
References: <CANy1k1i9bq-=gTHxo7m_qW_zXJqbxFs9vLBs7q=WKRUhxozJ_g@mail.gmail.com>
<mailman.64.1686176306.23016.python-list@python.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: individual.net 0XC4NGm3CNZBRrjZV8VsywZqjVTtIdw61TOJD8mytdfb6ukGSS
Cancel-Lock: sha1:EZ7Ztnbup1BQbBkYdYOD2V6UqSc=
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:91.0)
Gecko/20100101 Thunderbird/91.3.2
Content-Language: en-US
In-Reply-To: <mailman.64.1686176306.23016.python-list@python.org>
 by: Greg Ewing - Wed, 7 Jun 2023 23:58 UTC

On 8/06/23 10:18 am, Jason Friedman wrote:
> SyntaxError: name capture 'RANGE' makes remaining patterns unreachable

The bytecode compiler doesn't know that you intend RANGE
to be a constant -- it thinks it's a variable to bind a
value to.

To make this work you need to find a way to refer to the
value that isn't just a bare name. One way would be to
define your constants using an enum:

class Options(Enum):
RANGE = "RANGE"
MANDATORY = "MANDATORY"

match stuff:
case Options.RANGE:
...
case Options.MANDATORY:
...

--
Greg

Re: Match statement with literal strings

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

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: jsf80...@gmail.com (Jason Friedman)
Newsgroups: comp.lang.python
Subject: Re: Match statement with literal strings
Date: Wed, 7 Jun 2023 18:44:53 -0600
Lines: 53
Message-ID: <mailman.67.1686185106.23016.python-list@python.org>
References: <CANy1k1i9bq-=gTHxo7m_qW_zXJqbxFs9vLBs7q=WKRUhxozJ_g@mail.gmail.com>
<mailman.64.1686176306.23016.python-list@python.org>
<kecjtuFnbj5U1@mid.individual.net>
<CANy1k1jiiRpibxe1P3k5=2gtjOKGF_mP1A26ZLb9Y1fbSon=Pg@mail.gmail.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Trace: news.uni-berlin.de QxRWyueIj3kFPUvsj7HsCQOYLlo7SntOmsxNXU9fwx+g==
Return-Path: <jsf80238@gmail.com>
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=gmail.com header.i=@gmail.com header.b=K6Aqji9x;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.010
X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'variable': 0.05; '2023':
0.07; 'cc:addr:python-list': 0.09; 'compiler': 0.09; 'email
addr:python.org>': 0.09; 'thinks': 0.09; '&gt;': 0.14; 'cc:no real
name:2**0': 0.14; 'url:mailman': 0.15; 'constant': 0.16; 'greg':
0.16; 'mandatory': 0.16; 'patterns': 0.16; 'syntaxerror:': 0.16;
'wrote:': 0.16; 'name.': 0.19; 'cc:addr:python.org': 0.20; 'url-
ip:188.166.95.178/32': 0.25; 'url-ip:188.166.95/24': 0.25;
'url:listinfo': 0.25; 'cc:2**0': 0.25; 'url-ip:188.166/16': 0.25;
'intend': 0.26; 'jun': 0.26; "isn't": 0.27; 'email
addr:python.org&gt;': 0.28; 'it,': 0.29; 'am,': 0.31; 'url-
ip:188/8': 0.31; "doesn't": 0.32; 'python-list': 0.32; 'message-
id:@mail.gmail.com': 0.32; 'header:In-Reply-To:1': 0.34;
'received:google.com': 0.34; 'from:addr:gmail.com': 0.35; 'using':
0.37; "it's": 0.37; 'class': 0.37; 'way': 0.38; 'to.': 0.39;
'wed,': 0.39; 'define': 0.40; 'match': 0.40; 'to:none': 0.60;
'skip:o 10': 0.61; 'range': 0.64; 'your': 0.64; 'remaining': 0.69;
'you.': 0.71; 'bind': 0.84; 'capture': 0.84; 'email name:&lt
;python-list': 0.84; 'you.\xc2\xa0': 0.84
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20221208; t=1686185104; x=1688777104;
h=cc:subject:message-id:date:from:in-reply-to:references:mime-version
:from:to:cc:subject:date:message-id:reply-to;
bh=PJgubqy66wrl6Eg9NynxHiwpVXbmyWhDNfuGLQDbUYw=;
b=K6Aqji9x7/Al/yYA1xQeC9h8YwXhPmrtzBk+TcbCmmWRy9DhgiOcOEQdAfGfQMv2So
2/jqb8iabbW4zIyEI3EhLCGRR0W/++0sioSz3aSdlDtXwQUH1mu1MKVioaQ0s/xmfRFs
+4ueqtC1lHXuzBcl7KN3nXUZFlfVYbKI3KxfClJDjB8mrsBp/OI6W+3xhOn7DcJfUD9T
cWxxgQnJaS74AbxS0RtUu3QIfnxLnDFqeMYmvybJtjqep3oT6JofbP1rKlXO/31AqwFp
A2tqfXfkTVT9AI1qNA+/3XDsCpSW3IASV08rcCB2ygmJw4AVogHjb1w18G31BoaO/yOY
K9og==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20221208; t=1686185104; x=1688777104;
h=cc:subject:message-id:date:from:in-reply-to:references:mime-version
:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to;
bh=PJgubqy66wrl6Eg9NynxHiwpVXbmyWhDNfuGLQDbUYw=;
b=AMg2BTTzgniWfONUrezNAus+XIWYnsO1kKMkH29+8qDtipO17xbyShOsOYZHV/jC3+
iyGnfAOiD7j0eBaM1/WABFl6vJLEuJ7IEL2ACJ+T16weYTpcmjEAhFC3OlnUtRyT0UhF
pkHiuXIEYg+XGhBGZEOVvZS59Q1C6jaIZVA0WZ0AhWuyW+j4JVIvSp7ugqF23Qx13C8d
IZy2Cbsr4QnNEsk+ueU+K+uSdxqOXO90wAecg3VANob/4FiDewC6XtpDaUtQ4goZzMYv
vtBa3Cu8QIGrDbgfupuSU6mOJQbYP8982LRv96vWjSkNK00Ts/bdCrXvWqlPA05szGnq
uc8A==
X-Gm-Message-State: AC+VfDziFCVsa4UlFmO3vhW70wKWq5zVHb5rWkdMYdfIqDBsR/EvNPgZ
LlaD2PmAP8kKZCdvD57bD1o7KIOepZm7T+3VD9Cpbg7LyIg=
X-Google-Smtp-Source: ACHHUZ50pOtGNPOJLelssmiwkWXeSSJ1VTDNOEGMkaHSMunq3eqKuSfBAKppx6Asn9SgmEf1deX6WdcWB91xB59GWcQ=
X-Received: by 2002:a17:907:7b8e:b0:966:484a:335e with SMTP id
ne14-20020a1709077b8e00b00966484a335emr7862511ejc.43.1686185104199; Wed, 07
Jun 2023 17:45:04 -0700 (PDT)
In-Reply-To: <kecjtuFnbj5U1@mid.individual.net>
X-Content-Filtered-By: Mailman/MimeDel 2.1.39
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: <CANy1k1jiiRpibxe1P3k5=2gtjOKGF_mP1A26ZLb9Y1fbSon=Pg@mail.gmail.com>
X-Mailman-Original-References: <CANy1k1i9bq-=gTHxo7m_qW_zXJqbxFs9vLBs7q=WKRUhxozJ_g@mail.gmail.com>
<mailman.64.1686176306.23016.python-list@python.org>
<kecjtuFnbj5U1@mid.individual.net>
 by: Jason Friedman - Thu, 8 Jun 2023 00:44 UTC

>
> The bytecode compiler doesn't know that you intend RANGE
> to be a constant -- it thinks it's a variable to bind a
> value to.
>
> To make this work you need to find a way to refer to the
> value that isn't just a bare name. One way would be to
> define your constants using an enum:
>
> class Options(Enum):
> RANGE = "RANGE"
> MANDATORY = "MANDATORY"
>
> match stuff:
> case Options.RANGE:
> ...
> case Options.MANDATORY:
> ...
>

Got it, thank you.

On Wed, Jun 7, 2023 at 6:01 PM Greg Ewing via Python-list <
python-list@python.org> wrote:

> On 8/06/23 10:18 am, Jason Friedman wrote:
> > SyntaxError: name capture 'RANGE' makes remaining patterns unreachable
>
> The bytecode compiler doesn't know that you intend RANGE
> to be a constant -- it thinks it's a variable to bind a
> value to.
>
> To make this work you need to find a way to refer to the
> value that isn't just a bare name. One way would be to
> define your constants using an enum:
>
> class Options(Enum):
> RANGE = "RANGE"
> MANDATORY = "MANDATORY"
>
> match stuff:
> case Options.RANGE:
> ...
> case Options.MANDATORY:
> ...
>
> --
> Greg
>
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor