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

Make flag enums have singular names only (no plural name aliases)

    XMLWordPrintable

Details

    • Suggestion
    • Resolution: Unresolved
    • Not Evaluated
    • None
    • 6.4.0
    • Documentation, PySide
    • None
    • The environment doesn't matter in this case.

    • All

    Description

      The plural name aliases for flag enums in PySide6 are redundant. Let me explain with an example...

      >>> from PySide6.QtCore import Qt
      >>> Qt.TextInteractionFlags
      <flag 'TextInteractionFlag'>
      

      The plural name of the flag enum `TextInteractionFlag*s*` apparently exists as an alias for the singular name of the same flag enum `TextInteractionFlag`. This is redundant.

      But something interesting happens. If I have `Qt.TextInteractionFlags` in my VSCode IDE, then `Qt` is immediately marked with a red squiggly underline because I use the mypy extension. When my mouse pointer then hovers over the underlined `Qt`, a pop-up dialog window shows a hint that `"Type[Qt]" has no attribute "TextInteractionFlags"`.

      This is strange because using the plural name of the flag enum in the command line (see above) responds with the singular name of the same flag enum, so there must be an alias defined somewhere; otherwise, an `AttributeError` would be raised, of course.

      I searched the whole `QtCore.pyi` file and haven't found `TextInteractionFlag*s*` in the `Qt` namespace, I found only `TextInteractionFlag`.

      I have 3 questions now:

      1. Where are those aliases defined?
      2. Is it safe to use such aliases?
      3. Will such aliases be removed in the future?

      The PySide6 documentation lists only the singular names of the flag enums without listing their plural name aliases (such as `Qt.TextInteractionFlag*s*`, etc.), but the plural name aliases must exist somewhere. Are those aliases kept for backwards compatibility only and will be removed in the future and are not documented for this very same reason?

      The Qt documentation, however, is a different story. It, for example, lists the plural name as the flags of `Qt::TextInteractionFlags` enum and lists the singular name as an enum of `Qt::TextInteractionFlag`. Redundant, indeed. Or am I missing something?

      Why is there such a mess? I suggest to only have one name for flag enums, the singular name. I honestly believe that all plural name aliases should be removed in Qt and consequently in PySide (and in PyQt, too). I'd just stick with singular names for the flag enums, simple and straightforward.

      I have, however, read (can't rememeber where exactly) that aliases (in Qt, I believe) such as `Qt::AlignLeft` will be removed in favor of `Qt::AlignmentFlag::AlignLeft`. But here is yet another mess: `Qt::Alignment` is an alias for `Qt::AlignmentFlag`, so it is the same if you use `Qt::Alignment::AlignLeft`.

      There is no end to this mess. I wish Qt finally unifies this some day and removes all those "convenient" aliases which, in reality, only create ambiguous usage. This applies to PySide and PyQt as well.

      Attachments

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

        Activity

          People

            ctismer Christian Tismer
            pedantichacker Boštjan Mejak
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes