Consider the following code:
"""
5 or more space indentation and a ) or ] or }
"""
from __future__ import (barry_as_FLUFL,
annotations, # 5 or more space indentation inside parentheses
)
from typing import Literal
from PySide6.QtCore import QObject
egg = ['spam',
'egg'] # 5 or more space indentation inside brackets
spam = {'spam',
'egg'} # 5 or more space indentation inside braces
def bar(spam: Literal[')'],
egg: Literal['(']): # 5 or more space indentation inside parentheses
pass
class Spam(QObject):
"""
this line does NOT cause any trouble :-)
"""
class Egg:
pass
def spam(self) -> None:
self.tr('NOT in the Egg class!')
When I feed any of them to pyside6-lupdate, I get the following TS file:
<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE TS> <TS version="2.1"> <context> <name>Egg</name> <message> <source>NOT in the Egg class!</source> </message> </context> </TS>
The context name is incorrect. It happens if I have a line that is indented by more than 4 spaces (i.e., of imported stuff or docs, copyright, etc.) and inside parentheses/brackets/braces before the class. I got several cases here to test. Any single one of them reproduces the issue.
The same problem occurs with lupdate for PyQt5, and I guess that PySide2 may experience it as well.
| For Gerrit Dashboard: PYSIDE-2379 | ||||||
|---|---|---|---|---|---|---|
| # | Subject | Branch | Project | Status | CR | V |
| 489628,7 | lupdate: Improve indentation calculation for Python code | dev | qt/qttools | Status: MERGED | +2 | 0 |
| 490024,2 | lupdate: Improve indentation calculation for Python code | 6.6 | qt/qttools | Status: MERGED | +2 | 0 |
| 490025,2 | lupdate: Improve indentation calculation for Python code | 6.5 | qt/qttools | Status: MERGED | +2 | 0 |