-
-
Notifications
You must be signed in to change notification settings - Fork 34.1k
Open
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)type-featureA feature request or enhancementA feature request or enhancement
Description
Feature or enhancement
Proposal:
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
I am therefore suggesting to change the message to "class pattern must refer to a class".
See #103576 for a PR that previously changed this error message (from "… must be a type" to "… must be a class").
Has this already been discussed elsewhere?
This is a minor feature, which does not need previous discussion elsewhere
Links to previous discussion of this feature:
No response
Linked PRs
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)type-featureA feature request or enhancementA feature request or enhancement