Skip to content

Please, type hint this library. #960

Open
@elenakrittik

Description

@elenakrittik

Is your feature request related to a problem?

Currently it is not possible to use aiomysql without lots of # type: ignores or disabling some of the core type-checker rules. For example, pyright in strict mode starts giving errors on the first line of a typical aiomysql usage, because aiomysql.connect() parameters are not type hinted:

Type of "connect" is partially unknown
  Type of "connect" is "(host: str = "localhost", user: Unknown | None = None, password: str = "", db: Unknown | None = None, port: int = 3306, unix_socket: Unknown | None = None, charset: str = '', sql_mode: Unknown | None = None, read_default_file: Unknown | None = None, conv: Unknown = decoders, use_unicode: Unknown | None = None, client_flag: int = 0, cursorclass: type[Cursor] = Cursor, init_command: Unknown | None = None, connect_timeout: Unknown | None = None, read_default_group: Unknown | None = None, autocommit: bool = False, echo: bool = False, local_infile: bool = False, loop: Unknown | None = None, ssl: Unknown | None = None, auth_plugin: str = '', program_name: str = '', server_public_key: Unknown | None = None) -> _ConnectionContextManager"

Most other APIs aiomysql provides are also not type hinted and therefore fail type-checks too, permanently putting a big "no" on the usage of aiomysql in fully type-checked codebases.

Describe the solution you'd like

I understand proper type hints are pretty hard to make, thus as a first step i see type hinting public functions/classes/etc. without caring about internals much. This will make this library usable with type checkers, while internals can be type hinted gradually.

Describe alternatives you've considered

As was said before, to use aiomysql with type checkers you either need to:

  • Place # type: ignore at almost every line of code touching aiomysql; or
  • Disable some of the core checks type checkers offer, invalidating the very point itself of using them in first place.

One can perhaps make type stubs themselves, but nowadays typing support in Python ecosystem is seemed as a must for the majority of projects, or at least lots of developers think so from what i see, and thus i don't think that type stubs should be provided as an external addition.

Additional context

No response

Code of Conduct

  • I agree to follow the aio-libs Code of Conduct

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions