Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Please, type hint this library. #960

Open
1 task done
elenakrittik opened this issue Sep 2, 2023 · 1 comment
Open
1 task done

Please, type hint this library. #960

elenakrittik opened this issue Sep 2, 2023 · 1 comment

Comments

@elenakrittik
Copy link

elenakrittik commented Sep 2, 2023

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
@trim21
Copy link

trim21 commented Mar 23, 2024

I would be happy to contribute a PR for this.

@elenakrittik elenakrittik changed the title Type hint this module. Please, type hint this library. Mar 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants