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.
Currently, I'm getting a bunch of extremely frustrating type checker errors since the return type of the
parsefunction 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
Anyto each affected function, so that type checkers think all attributes are there. This is what the stub file for the builtinjsonmodule does for theirloadandloads. Of course, it would then be the user's responsibility to use only the properties and methods they know are present.