python / python/cpython

Accidental name bindings with structural pattern matching

Open
#93,059 7 comments 2 reactions 1 assignee View on GitHub

@brandtbucher is already working on this.

Since May 22, 2022.

interpreter-core type-bug
Dominant language
Python
Stars
77.2k
Forks
36k
PR merge metrics
PR metrics pending

Description

Bug report

Your environment

  • CPython versions tested on: 3.10.2, 3.11.0a6
  • Operating system and architecture: macOS Monterey, Version 12.3.1. Mac mini running M1, Apple silicon.

Steps to reproduce:

Run the code in bug.py, attached.

bug.zip

The output on my Mac mini is:

% python bug.py
Cheese Sandwich

Search for 'match' in the code. Notice that one of the terms matches
the only str in the list, "Cheese Sandwich". Later we create a dataclass
of type PersonHeight. On the last line of the file, we print the type
of one of the fields in a PersonHeight object. Note that it is not <class 'str'> as it should be,
but "Cheese Sandwich"

If we comment out the match expression, we get the correct behavior
(see comment below in code)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.