Skip to content

gh-144702: Use standard terminology in class pattern error message#144703

Merged
AlexWaygood merged 1 commit intopython:mainfrom
sharkdp:error-message-class-pattern
Feb 19, 2026
Merged

gh-144702: Use standard terminology in class pattern error message#144703
AlexWaygood merged 1 commit intopython:mainfrom
sharkdp:error-message-class-pattern

Conversation

@sharkdp
Copy link
Contributor

@sharkdp sharkdp commented Feb 11, 2026

When trying to use a class pattern to match on a non-class object, we currently get the following error message:

Traceback (most recent call last):
  File "/tmp/test.py", line 2, in <module>
    case len():
         ~~~^^
TypeError: called match pattern must be a class

The terminology "called match pattern" here is a bit confusing. It's not used anywhere else as far as I can tell, and for a beginner, it might read like something is actually being called here.

The documentation consistently refers to these patterns as "class patterns":

Here, we change this message to "class pattern must refer to a class".

When trying to use a class pattern to match on a non-class object, we
currently get the following error message:

    Traceback (most recent call last):
      File "/tmp/test.py", line 2, in <module>
        case len():
             ~~~^^
    TypeError: called match pattern must be a class

The terminology "called match pattern" here is a bit confusing. It's not
used anywhere else as far as I can tell, and for a beginner, it might
read like something is actually being called here.

The documentation consistently refers to these patterns as "class
patterns":

* https://docs.python.org/3/reference/compound_stmts.html#class-patterns
* https://peps.python.org/pep-0635/#class-patterns
* https://docs.python.org/3/library/ast.html#ast.MatchClass
* https://docs.python.org/3/reference/datamodel.html#customizing-positional-arguments-in-class-pattern-matching

Here, we change this message to "class pattern must refer to a class".
Copy link
Member

@johnslavik johnslavik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume we don't need a test. Without the entire check, _PyEval_MatchClass will still appropriately fail with a TypeError.

@AlexWaygood AlexWaygood merged commit 1d09916 into python:main Feb 19, 2026
64 checks passed
@AlexWaygood
Copy link
Member

Thanks for the PR! 😃

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

Comments