Skip to content
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 6 commits into from
Nov 29, 2022
Merged

Fixes for newer astroid versions #101

merged 6 commits into from
Nov 29, 2022

Conversation

alexmojaki
Copy link
Contributor

Fixes #70 and #79

  • Removes astroid version constraint from tests, to test the latest astroid version for that Python version
  • Handles classes moving from astroid.node_classes to astroid.nodes.
  • When marking tokens, ignores empty astroid slices which mess up the positions of their parent nodes..
  • Ignores incorrect tuple of astroid slices in test_slices.
  • Ignores Position when asserting equal astroid nodes.

@alexmojaki
Copy link
Contributor Author

alexmojaki commented Oct 30, 2022

@palfrey I need mypy help

Copy link
Member

@dsagal dsagal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!!

@@ -88,6 +83,9 @@ def _visit_after_children(self, node, parent_token, token):
first = token
last = None
for child in cast(Callable, self._iter_children)(node):
# astroid slices have especially wrong positions, we don't want them to corrupt their parents.
if util.is_empty_astroid_slice(child):
Copy link
Member

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 in util.py? (Perhaps that would be wrong, but seems this is done for some nodes already.)

Copy link
Contributor Author

@alexmojaki alexmojaki Nov 25, 2022

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.

asttokens/util.py Outdated Show resolved Hide resolved
@@ -814,6 +819,10 @@ def assert_nodes_equal(self, t1, t2):
else:
self.assertEqual(type(t1), type(t2))

if isinstance(t1, AstroidPosition):
Copy link
Member

Choose a reason for hiding this comment

The 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 :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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

Copy link
Member

@dsagal dsagal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent!

@alexmojaki alexmojaki merged commit ee35c90 into master Nov 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants