Uploaded image for project: 'Qt for Python'
  1. Qt for Python
  2. PYSIDE-2542

QtCore.QSettings.value should infer return type from type parameter

    XMLWordPrintable

Details

    • Suggestion
    • Resolution: Won't Do
    • P4: Low
    • None
    • 6.5.3, 6.6.1
    • Type hints
    • None
    • Python 3.11.6
      Windows 10 Version 10.0.19045 Build 19045

    Description

      As title says: QtCore.QSettings.value should infer return type from type parameter by adding a top overload with a TypeVar

      The overload would look something like this:

      _T = TypeVar("_T")  # typing.TypeVar, not ast.TypeVar
      class QSettings(PySide6.QtCore.QObject):
          ...
          @overload
          def value(self, arg__1: str, defaultValue: _T, type: type[_T]) -> _T: ...
      

      So that casting isn't needed when using:

      value = cast(
              bool,
              QtCore
              .QSettings("AutoSplit", "Check For Updates On Open")
              .value("check_for_updates_on_open", True, type=bool),
          )
      

      Attachments

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              ctismer Christian Tismer
              avasam Samuel Therrien
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes