Skip to content

Literals trigger hard to understand errors #115

@msehnout

Description

@msehnout

Hi,

I found 2 literals that trigger an error: in and On Hold. I saw a closed issue for "in", but I'm not sure it was fixed or just dismissed.

Anyway this is the error message:

    return parse(source_str)
           ^^^^^^^^^^^^^^^^^
libcst._exceptions.ParserSyntaxError: Syntax Error @ 1:1.
parser error: error at 1:2: expected one of (, *, +, -, ..., AWAIT, EOF, False, NUMBER, None, True, [, break, continue, lambda, match, not, pass, ~

in
^

Could bump-pydantic produce more helpful error message, e.g. with the whole line and line number? I took me a while to understand which "in" is the problem, because running grep in produced a lot of output :)

These are the reproducers:
1.

from typing import Literal

from pydantic import BaseModel


class MySuperPhoneObject(BaseModel):

    state: Literal["Closed", "On Hold", "Speaking", "Ringing"]

from typing import Literal

from pydantic import BaseModel


class MySuperPBXQueueObject(BaseModel):

    state: Literal["in", "out"]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions