aio-libs / aiomysql

aiomysql is a library for accessing a MySQL database from the asyncio
https://aiomysql.rtfd.io
MIT License
1.72k stars 254 forks source link

Please, type hint this library. #960

Open elenakrittik opened 10 months ago

elenakrittik commented 10 months ago

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:

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

trim21 commented 3 months ago

I would be happy to contribute a PR for this.