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

QSemaphore.try_acquire() takes no arguments when using snake_case

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P2: Important
    • 6.8.0
    • 6.7, 6.7.2
    • PySide, Type hints
    • None
    • Windows
    • f48433db9 (dev)

    Description

      When using the snake_case feature in PySide6, I am getting a TypeError whenever I try to call try_acquire() with any arguments. The following code consistently reproduces the issue for me with the accompanying error message:

      import sys
      
      from PySide6.QtCore import QSemaphore
      from PySide6.QtWidgets import QApplication, QMainWindow, QWidget
      
      from __feature__ import snake_case
      
      
      class MainWindow(QMainWindow):
          def __init__(self, parent: QWidget | None = None) -> None:
              super().__init__(parent)
      
              semaphore = QSemaphore(1)
              print(f"{semaphore.try_acquire(1)=}")
      
      
      if __name__ == "__main__":
          app = QApplication()
          window = MainWindow()
          window.show()
          sys.exit(app.exec())

       

      Traceback (most recent call last):
        File "errordemo.py", line 19, in <module>
          window = MainWindow()
                   ^^^^^^^^^^^^
        File "errordemo.py", line 14, in __init__
          print(f"{semaphore.try_acquire(1)=}")
                   ^^^^^^^^^^^^^^^^^^^^^^^^
      TypeError: QSemaphore.try_acquire() takes no arguments (1 given)

       

      Now, the QSemaphore type hints for the snake_case feature did indicate that try_acquire() takes no arguments, but I'd originally thought this was just a bug in type hint generation:

      class QSemaphore(Shiboken.Object):
      
          def __init__(self, n: int = ...) -> None: ...
      
          def acquire(self, n: int = ...) -> None: ...
          def available(self) -> int: ...
          def release(self, n: int = ...) -> None: ...
          def try_acquire(self) -> bool: ... 

       

      I suspect this bug is being caused by the existence of a snake_case try_acquire() method in the standard camelCase class definition:

      class QSemaphore(Shiboken.Object):
      
          def __init__(self, n: int = ...) -> None: ...
      
          def acquire(self, n: int = ...) -> None: ...
          def available(self) -> int: ...
          def release(self, n: int = ...) -> None: ...
          @overload
          def tryAcquire(self, n: int, timeout: int) -> bool: ...
          @overload
          def tryAcquire(self, n: int, timeout: Union[PySide6.QtCore.QDeadlineTimer, PySide6.QtCore.QDeadlineTimer.ForeverConstant, int]) -> bool: ...
          @overload
          def tryAcquire(self, n: int = ...) -> bool: ...
          def try_acquire(self) -> bool: ... 

      When snake_case is enabled, what I would expect is for the tryAcquire() and try_acquire() methods to be merged into a single try_acquire() method with four overloads.

      Attachments

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

        Activity

          People

            kleint Friedemann Kleint
            bflecker Bryton Flecker
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes