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

Type stub for QmlElement (and others) obscure decorated type from type checkers

    XMLWordPrintable

Details

    • Bug
    • Resolution: Duplicate
    • Not Evaluated
    • None
    • 6.8.1
    • Type hints
    • None

    Description

      The current type hints for QmlElement, QmlUncreatable, QmlAnonymous, and QmlSingleton (and possibly others) all have an argument type of `object` and a return type of `object`. This causes problems with type checkers as these should all take some type as the argument and return that same type.

      You can get seemingly correct behavior by patching `QtQml.pyi` to include, for example:

      _UncreatableT = typing.TypeVar('_UncreatableT')
      def QmlUncreatable(reason: str | None = None) -> typing.Callable[[_UncreatableT], _UncreatableT]: ...
      
      _AnonymousT = typing.TypeVar("_AnonymousT")
      def QmlAnonymous(arg__1: _AnonymousT) -> _AnonymousT: ...
      
      _ElementT = typing.TypeVar("_ElementT")
      def QmlElement(arg__1: _ElementT) -> _ElementT: ...
      
      _SingletonT = typing.TypeVar("_SingletonT")
      def QmlSingleton(arg__1: _SingletonT) -> _SingletonT: ... 

      There may be a cleaner way to do this, but this seems to work.

      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
              jtc9242 Joel Collins
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes