Uploaded image for project: 'Python Driver'
  1. Python Driver
  2. PYTHON-3992

Use the new type defaults for Generics

    • Type: Icon: Task Task
    • Resolution: Unresolved
    • Priority: Icon: Unknown Unknown
    • 5.0
    • Affects Version/s: None
    • Component/s: None
    • None
    • Hide

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?

      PEP 696 adds type defaults for TypeVar. It is available in Python 3.12 and loosely supported with the typing_extensions that comes in mypy 1.4+ (technically typing_extensions>=4.4.0).

      However, with the next release of mypy we get *exactly* the behavior we want. pyright has supported the new syntax since at least the version we're using in our tests currently.

      I tried the code snippet in VSCode and PyLance picks up the same types as the mypy }} playground. I believe the only places we'd need to use {{@overload are the constructors for generic classes that take an optional codec_options, and the with_options methods.

      With mypy 1.3.0 -1.5.1, we would have the same behavior as our generics have today. With the next release of mypy we should be able to support strict typing and greatly simplify both our typing implementation and its usage by users.

      Assuming this works, we could close PYTHON-3980.

            Assignee:
            Unassigned Unassigned
            Reporter:
            steve.silvester@mongodb.com Steve Silvester
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: