Skip to content

Upgrade to Python 3.10  #1

@JackGeraghty

Description

@JackGeraghty

Why upgrade to 3.10? Mostly quality of life improvements to python. This update would also encompass features introduced in Python 3.9 like generic type hinting, dictionary merging and updating operators and some string prefix and suffix removal functions.

Python 3.10 then introduces some more quality of life like better error messages, pattern matching (a more powerful switch statement) and type aliasing

Overall I think it should bring features that will improve the code base, make it all more readable and enable some new node functionality.

# Generic Type Hinting
# <= 3.8
my_list: list[str] # error
my_dict: dict[str, int] # error

from typings import List, Dict

my_dict: Dict[str, int] # ok
my_list: List[str] # ok

# > 3.8
my_list: list[str] # ok
my_dict: dict[str, int] # ok

# Dictionary Merging
x = {"key1": "value1 from x", "key2": "value2 from x"}
y = {"key2": "value2 from y", "key3": "value3 from y"}
z = x | y
# z = {'key1': 'value1 from x', 'key2': 'value2 from y', 'key3': 'value3 from y'}
# Patter matching
class Point:
    x: int
    y: int

def location(point):
    match point:
        case Point(x=0, y=0):
            print("Origin is the point's location.")
        case Point(x=0, y=y):
            print(f"Y={y} and the point is on the y-axis.")
        case Point(x=x, y=0):
            print(f"X={x} and the point is on the x-axis.")
        case Point():
            print("The point is located somewhere else on the plane.")
        case _:
            print("Not a point")

# Type Aliasing
StrCache = 'Cache[str]'  # a type alias

# Better error messages
def foo():
    if lel:
        x = 2
  File "<stdin>", line 3
    x = 2
    ^
IndentationError: expected an indented block after 'if' statement in line 2

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions