[Python-Dev] Re: PEP 622 (match statement) playground

2020-07-08 Thread Kerwin Sun
I tried with this code:
```
from dataclasses import dataclass

@dataclass
class Point:
x: int
y: int

z = 41

def whereis(point):
w = 23
match point:
case Point(0, 0):
print("Origin")
case Point(0, y):
print(f"Y={y}")
case Point(x, 0):
print(f"X={x}")
case Point():
print("Somewhere else")
case 23:
print("Not the answer")
case w:
 print("Not the answer, local w")
case z:
 print("The answer")
case _:
 print("other")
whereis(42)
```

The output is:
```
Not the answer, local w
<>:23: SyntaxWarning: unguarded name capture pattern makes remaining cases 
unreachable
<>:23: SyntaxWarning: unguarded name capture pattern makes remaining cases 
unreachable
:23: SyntaxWarning: unguarded name capture 
pattern makes remaining cases unreachable
  case w:
```

I except this function to return "other", But it seems not.
___
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/463BWHAOQAK4E5FWKYNZYSXXVGWB2T2Z/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-Dev] Re: PEP 622 (match statement) playground

2020-07-08 Thread Kerwin Sun
I tried with this code:
```
from dataclasses import dataclass

@dataclass
class Point:
x: int
y: int

z = 41

def whereis(point):
w = 23
match point:
case Point(0, 0):
print("Origin")
case Point(0, y):
print(f"Y={y}")
case Point(x, 0):
print(f"X={x}")
case Point():
print("Somewhere else")
case 23:
print("Not the answer")
case w:
 print("Not the answer, local w")
case z:
 print("The answer")
case _:
 print("other")
whereis(42)
```

It retuend:
```
Not the answer, local w
<>:23: SyntaxWarning: unguarded name capture pattern makes remaining cases 
unreachable
<>:23: SyntaxWarning: unguarded name capture pattern makes remaining cases 
unreachable
:23: SyntaxWarning: unguarded name capture 
pattern makes remaining cases unreachable
  case w:
```

It seems not the return I except.
___
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/SFY23W4UTT7VJZAW6WLPJ3UQEHUCXMQB/
Code of Conduct: http://python.org/psf/codeofconduct/