Skip to content

Error when executing the sample in chapter 4.6 #106625

@RustyNail

Description

@RustyNail

Documentation

This is a pull request for the sample code in section 4.6.

I ran the following based on the sample code and got an error.

The sample code in the tutorial may be an excerpt of some code.
However, given that we will try "Point(1, var)" immediately following, I believe the user will easily understand that there is a necessary dataclass import statement.

Executed code :

class Point:
    x: int
    y: int

def where_is(point):
    match point:
        case Point(x=0, y=0):
            print("Origin")
        case Point(x=0, y=y):
            print(f"Y={y}")
        case Point(x=x, y=0):
            print(f"X={x}")
        case Point():
            print("Somewhere else")
        case _:
            print("Not a point")

## Added code
p = Point(1, 1)

Errors that occurred :

    p = Point(1, 1)
        ^^^^^^^^^^^
TypeError: Point() takes no arguments

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    docsDocumentation in the Doc dir

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions