Skip to content

Commit

Permalink
Merge pull request #22 from ISISComputingGroup/fix_astroid_crash
Browse files Browse the repository at this point in the history
Deorphanize Node
  • Loading branch information
KathrynBaker authored Feb 13, 2025
2 parents abb695a + 63d5cdb commit c4c5871
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/genie_python/scanning_instrument_pylint_plugin.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import astroid
from astroid import MANAGER, NodeNG
from astroid import MANAGER


def register(linter: None) -> None:
Expand All @@ -22,7 +22,7 @@ def transform(cls: astroid.ClassDef) -> None:
name=public_method.name,
lineno=0,
col_offset=0,
parent=NodeNG(lineno=0, col_offset=0, parent=None, end_lineno=0, end_col_offset=0),
parent=cls.parent,
end_lineno=0,
end_col_offset=0,
)
Expand Down
21 changes: 21 additions & 0 deletions tests/test_script_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
from __future__ import absolute_import

import builtins
import contextlib
import io
import os
import shutil
import sys
Expand Down Expand Up @@ -612,3 +614,22 @@ def test_GIVEN_unused_import_WHEN_pyright_script_checker_called_THEN_no_error(se
self.checker, self.machine, script_lines, no_pylint=True
) as errors:
self.assertEqual(errors, [])

def test_GIVEN_scanning_instrument_WHEN_calling_pylint_THEN_pylint_does_not_crash(self):
# Pylint should not complain about this as the method from a class
# deriving from "ScanningInstrument" should get added to it's parents'
# locals by the scanning_instrument_pylint_plugin.
script_lines = [
"class ScanningInstrument(): pass\n",
"class Larmor(ScanningInstrument):\n",
" def foo(self): pass\n",
]

captured_stderr = io.StringIO()
with contextlib.redirect_stderr(captured_stderr):
with CreateTempScriptAndReturnErrors(
self.checker, self.machine, script_lines
) as errors:
self.assertEqual(errors, [])

self.assertEqual(captured_stderr.getvalue(), "")

0 comments on commit c4c5871

Please sign in to comment.