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: Unresolved
    • Not Evaluated
    • None
    • 6.6.2
    • Type hints
    • None

    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

        For Gerrit Dashboard: PYSIDE-2624
        # Subject Branch Project Status CR V

        Activity

          People

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

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There is 1 open Gerrit change