New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixes for newer astroid versions #101
Merged
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c30bd05
Fix tests for newest astroid
alexmojaki 5c7e360
Specifically ignore empty slices
alexmojaki 32b476b
comment on astroid_node_classes
alexmojaki 8a01fbc
mypy
alexmojaki 586ca78
coverage
alexmojaki 17fb607
fix is_empty_astroid_slice
alexmojaki File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
try: | ||
from astroid import nodes as astroid_node_classes | ||
|
||
# astroid_node_classes should be whichever module has the NodeNG class | ||
from astroid.nodes import NodeNG | ||
except Exception: | ||
try: | ||
from astroid import node_classes as astroid_node_classes | ||
from astroid.node_classes import NodeNG | ||
except Exception: # pragma: no cover | ||
astroid_node_classes = None | ||
NodeNG = None | ||
|
||
__all__ = ["astroid_node_classes", "NodeNG"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,11 @@ | |
|
||
from . import tools | ||
|
||
try: | ||
from astroid.nodes.utils import Position as AstroidPosition | ||
except Exception: | ||
AstroidPosition = () | ||
|
||
|
||
class TestMarkTokens(unittest.TestCase): | ||
maxDiff = None | ||
|
@@ -230,7 +235,7 @@ def test_deep_recursion(self): | |
|
||
def test_slices(self): | ||
# Make sure we don't fail on parsing slices of the form `foo[4:]`. | ||
source = "(foo.Area_Code, str(foo.Phone)[:3], str(foo.Phone)[3:], foo[:], bar[::2, :], [a[:]][::-1])" | ||
source = "(foo.Area_Code, str(foo.Phone)[:3], str(foo.Phone)[3:], foo[:], bar[::2, :], bar2[:, ::2], [a[:]][::-1])" | ||
m = self.create_mark_checker(source) | ||
self.assertIn("Tuple:" + source, m.view_nodes_at(1, 0)) | ||
self.assertEqual(m.view_nodes_at(1, 1), | ||
|
@@ -243,7 +248,7 @@ def test_slices(self): | |
# important, so we skip them here. | ||
self.assertEqual({n for n in m.view_nodes_at(1, 56) if 'Slice:' not in n}, | ||
{ "Subscript:foo[:]", "Name:foo" }) | ||
self.assertEqual({n for n in m.view_nodes_at(1, 64) if 'Slice:' not in n}, | ||
self.assertEqual({n for n in m.view_nodes_at(1, 64) if 'Slice:' not in n and 'Tuple:' not in n}, | ||
{ "Subscript:bar[::2, :]", "Name:bar" }) | ||
|
||
def test_adjacent_strings(self): | ||
|
@@ -814,6 +819,10 @@ def assert_nodes_equal(self, t1, t2): | |
else: | ||
self.assertEqual(type(t1), type(t2)) | ||
|
||
if isinstance(t1, AstroidPosition): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just checking that this is a separate kind of node and not a base class for everything in new astroid :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's not a node, it's this: class Position(NamedTuple):
"""Position with line and column information."""
lineno: int
col_offset: int
end_lineno: int
end_col_offset: int |
||
# Ignore the lineno/col_offset etc. from astroid | ||
return | ||
|
||
if isinstance(t1, (list, tuple)): | ||
self.assertEqual(len(t1), len(t2)) | ||
for vc1, vc2 in zip(t1, t2): | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might it be a better alternative to filter out empty slices in
iter_children_astroid
inutil.py
? (Perhaps that would be wrong, but seems this is done for some nodes already.)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just tried that, it didn't work. Other places need those child nodes to be included.