abulka/pynsource

Variable annotation triggers exception 'Subscript' object has no attribute 'id'

gjdm opened this issue · 5 comments

gjdm commented

Variable annotation (e.g. "self.pages: List[SnapFilterView2D] = list()") triggers exception 'Subscript' object has no attribute 'id'

image

gjdm

Thank you for reporting this.

Tried to reproduce this running under Python 3.9 parsing the following:

class A:
    def method1(self):
        self.pages: List[SnapFileView2D] = list()

and got no errors.

Hmm - perhaps this error only happens with lower version of Python - will need to check. As it stands, it looks promising that no changes to the Pynsource parser are needed, only a Python version bump. That is, assuming the above source code reproduces the problem.

Update: Tricky variable annotation, Actually turns out that on my mac, it used to fail ONLY in Python 3.9 but passed in 3.7 and 3.8.

Tested parsing this on Mac using official release which uses Python 3.7 internally - worked ok.

But on Linux the official snap release does exhibit the problem, but running under Python 3.7 from source code does not. Mysterious. Will investigate further.

Changed visit_AnnAssign() in parser to fix this, passes now under all Python versions.

Latest master branch and 1.78 beta binary release should have fixed this.
Official 1.78 release only a few days away.