On 1 Jul 2020, at 17:58, Guido van Rossum wrote:

If you are interested in learning more about how PEP 622 would work in
practice, but don't feel like compiling a Python 3.10 fork from source,
here's good news for you.

In a hurry?
https://mybinder.org/v2/gh/gvanrossum/patma/master?urlpath=lab/tree/playground-622.ipynb

If I change the example code to:

---------------------------------------------------
from dataclasses import dataclass

@dataclass
class Point:
    x: int
    y: int

z = 42

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 .w:
            print("Not the answer")
        case .z:
            print("The answer")
        case z:
            print("Not a point")
---------------------------------------------------

whereis(42)


gives me:

---------------------------------------------------
UnboundLocalError Traceback (most recent call last)
<ipython-input-16-3257cdeaff94> in <module>
----> 1 whereis(42)

<ipython-input-13-35ff7b1c0f2f> in whereis(point)
     10 def whereis(point):
     11     w = 23
     12     match point:
     13         case Point(0, 0):
     14             print("Origin")
     15         case Point(0, y):
     16             print(f"Y={y}")
     17         case Point(x, 0):
     18             print(f"X={x}")
     19         case Point():
     20             print("Somewhere else")
     21         case .w:
     22             print("Not the answer")
---> 23         case .z:
     24             print("The answer")
     25         case z:
     26             print("Not a point")

UnboundLocalError: local variable 'z' referenced before assignment
---------------------------------------------------

This looks strange to me. In all other cases of variable lookup the global variable z would be found.

whereis(23) however works.

[...]

Servus,
   Walter
_______________________________________________
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/6OLWD67D7EFBM6UHGQHZHS7MM22QE4N2/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to