Skip to content

Commit c4c5871

Browse files
authored
Merge pull request #22 from ISISComputingGroup/fix_astroid_crash
Deorphanize Node
2 parents abb695a + 63d5cdb commit c4c5871

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

src/genie_python/scanning_instrument_pylint_plugin.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import astroid
2-
from astroid import MANAGER, NodeNG
2+
from astroid import MANAGER
33

44

55
def register(linter: None) -> None:
@@ -22,7 +22,7 @@ def transform(cls: astroid.ClassDef) -> None:
2222
name=public_method.name,
2323
lineno=0,
2424
col_offset=0,
25-
parent=NodeNG(lineno=0, col_offset=0, parent=None, end_lineno=0, end_col_offset=0),
25+
parent=cls.parent,
2626
end_lineno=0,
2727
end_col_offset=0,
2828
)

tests/test_script_checker.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
from __future__ import absolute_import
1717

1818
import builtins
19+
import contextlib
20+
import io
1921
import os
2022
import shutil
2123
import sys
@@ -612,3 +614,22 @@ def test_GIVEN_unused_import_WHEN_pyright_script_checker_called_THEN_no_error(se
612614
self.checker, self.machine, script_lines, no_pylint=True
613615
) as errors:
614616
self.assertEqual(errors, [])
617+
618+
def test_GIVEN_scanning_instrument_WHEN_calling_pylint_THEN_pylint_does_not_crash(self):
619+
# Pylint should not complain about this as the method from a class
620+
# deriving from "ScanningInstrument" should get added to it's parents'
621+
# locals by the scanning_instrument_pylint_plugin.
622+
script_lines = [
623+
"class ScanningInstrument(): pass\n",
624+
"class Larmor(ScanningInstrument):\n",
625+
" def foo(self): pass\n",
626+
]
627+
628+
captured_stderr = io.StringIO()
629+
with contextlib.redirect_stderr(captured_stderr):
630+
with CreateTempScriptAndReturnErrors(
631+
self.checker, self.machine, script_lines
632+
) as errors:
633+
self.assertEqual(errors, [])
634+
635+
self.assertEqual(captured_stderr.getvalue(), "")

0 commit comments

Comments
 (0)