Skip to content

Annotate load/loads/parse return value as Any #107

Description

@jonathandung

Currently, I'm getting a bunch of extremely frustrating type checker errors since the return type of the parse function was inferred to be something like (Unknown | Any | list[Unknown | Any | list[Unknown | Any | list[Unknown] | bool | None] | bool | None] | bool | None), even if I know the json5 I'm parsing is a top-level object. The above type doesn't have the required method, and I don't want to use # type: ignore[attr-defined,reportOptionalMemberAccess,reportAttributeAccessIssue] every time.

I propose to add an inline return type annotation of Any to each affected function, so that type checkers think all attributes are there. This is what the stub file for the builtin json module does for their load and loads. Of course, it would then be the user's responsibility to use only the properties and methods they know are present.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions