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

Stubs should reflect the fact that functions do not take keyword arguments

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • Not Evaluated
    • None
    • 6.6.2
    • Type hints
    • None
    • 5825e86a3 (dev), 5c92412b2 (6.8)

    Description

      Type checkers/IDEs propose keyword arguments for PySide function calls, but these do not work:

      python -c "from PySide6.QtCore import QUrl; QUrl.setIdnWhitelist(arg1=[''])"
      Traceback (most recent call last):
        File "<string>", line 1, in <module>
      TypeError: QUrl.setIdnWhitelist() takes no keyword arguments
      

      I think PySide stubs should use the positional-only syntax which was introduced in Python 3.8 (https://peps.python.org/pep-0570/). Here's some example code showing the issue:
       

      from PySide6.QtCore import QUrl
      from collections.abc import Sequence
      
      # this works
      QUrl.setIdnWhitelist([""])
      
      # QtCore.pyi:
      # def def setIdnWhitelist(arg__1: Sequence[str]) -> None: ...
      
      # this fails
      QUrl.setIdnWhitelist(arg__1=[""])
      # TypeError: QUrl.setIdnWhitelist() takes no keyword arguments
      
      # Using "/" lets type checkers know that parameters should be keyword-only
      def mySetIdnWhitelist(arg__1: Sequence[str], /) -> None: ...
      # this is reported by type checkers
      mySetIdnWhitelist(arg__1=[""])
       

       

      Attachments

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

        Activity

          People

            crmaurei Cristian Maureira-Fredes
            bers bers bers
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes