Content-Length: 301101 | pFad | https://github.com/python/cpython/issues/100530

99 Confusing error message when attempting to pass a newtype as a match pattern · Issue #100530 · python/cpython · GitHub
Skip to content

Confusing error message when attempting to pass a newtype as a match pattern #100530

@not-my-profile

Description

@not-my-profile
from typing import NewType

T = NewType('T', str)

match 'test':
    case T(): ...

fails with:

Traceback (most recent call last):
  File "/tmp/foo.py", line 6, in <module>
    case T(): ...
         ^^^
TypeError: called match pattern must be a type

The error message is confusing because T is a type. The error message should probably say class instead of type, since as per the specification it's a class pattern.

Linked PRs

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions









    ApplySandwichStrip

    pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


    --- a PPN by Garber Painting Akron. With Image Size Reduction included!

    Fetched URL: https://github.com/python/cpython/issues/100530

    Alternative Proxies:

    Alternative Proxy

    pFad Proxy

    pFad v3 Proxy

    pFad v4 Proxy