Skip to content

Introduce types (replace stubs in typeshed) #953

Closed

Description

@darxriggs

Now that Python 3.6 is the minimum required Python version, it would be a good idea to maintain the types that are currently maintained in typeshed (see #524) directly in this library. Otherwise they easily get out of sync which is already the current state unfortunately.

Activity

  1. changed the title [-]Introduce types[/-] [+]Introduce types (replace stubs in typeshed)[/+] on Jan 23, 2021
  2. methane commented on Jan 24, 2021

    @methane
    Member

    I still don't like it. I am waiting to minimum supported version become Python 3.10. See python/cpython#23316

    Or at least Python 3.7; we can use from __future__ import annotations.

    Otherwise they easily get out of sync which is already the current state unfortunately.

    Why it's easy? DB-API is very stable. And other APIs are not important for end-users.
    I suppose you typed so much.

  3. Akuli commented on Jul 8, 2021

    @Akuli

    You can have type hints without from __future__ import annotations; they just have to be written so that the interpreter understands them. For example, you write from typing import Optional, List and then annotate things with Optional[str] or List[int], instead of using the newer str | None or list[int] syntax, available with from __future__ import annotations. But that said, if you want to do type hints once and not have to change them much afterwards, it can be better to wait for 3.7.

    Also, I don't see what that pull request has to do with type hints in pymysql. It appears to change something much lower-level than a Python library needs to care about.

  4. methane commented on Jul 9, 2021

    @methane
    Member

    It increase memory usage and time for import.

  5. Akuli commented on Jul 9, 2021

    @Akuli

    Python caches modules, so if pymysql uses import typing anywhere at all, it doesn't matter much whether it's used in many files or just one. Even with from __future__ import annotations, you will occasionally need something from typing, such as Any, Generic, TypeVar, overload or NoReturn, all of which are currently used in the typeshed PyMySQL stubs. You can generally put stuff like that under if TYPE_CHECKING:, but TYPE_CHECKING must be imported from typing, so you will need to load typing anyway.

    We are talking about approximately 5% more time, assuming no other libraries used than PyMySQL, or about 2% if you use PyMySQL and requests, for example. On my system:

    • python3 -c "import pymysql" takes 55ms
    • python3 -c "import pymysql, typing" takes 58ms
    • python3 -c "import pymysql, requests" takes 145ms

    I don't know of a good way to measure memory usage, so I didn't check that.

  6. locked as resolved and limited conversation to collaborators on Jul 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions