Skip to content

Fix recursion error for inference of self-referencing class attribute#1392

Merged
Pierre-Sassoulas merged 4 commits intopylint-dev:mainfrom
DanielNoord:recursion
Feb 21, 2022
Merged

Fix recursion error for inference of self-referencing class attribute#1392
Pierre-Sassoulas merged 4 commits intopylint-dev:mainfrom
DanielNoord:recursion

Conversation

@DanielNoord
Copy link
Copy Markdown
Collaborator

@DanielNoord DanielNoord commented Feb 11, 2022

Steps

  • For new features or bug fixes, add a ChangeLog entry describing what your PR does.
  • Write a good description on what the PR does.

Description

This will close when merged pylint-dev/pylint#5408.

Type of Changes

Type
🐛 Bug fix

Related Issue

Copy link
Copy Markdown
Member

@Pierre-Sassoulas Pierre-Sassoulas left a comment

Choose a reason for hiding this comment

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

The actual change looks great, but I don't think we should change the way we currentely import typing and nodes.

Comment thread astroid/inference_tip.py Outdated

import typing

from typing import Any, Callable, Dict, Iterator, List, Optional, Tuple, Type, Union
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It's imported this way in astroid because List, Dict, and Tuple are also astroid.nodes so it can become confusing. It's probably worth it to stay consistent accross the code base.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

In this file we only use 2 nodes and a lot of different typing stuff. That's why I opted to do it the other way around in this file.

I'm fine with reverting!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Let's keep the old imports (at least for class name that are also astroid nodes).

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Reverted to only import typing.

Comment thread astroid/inference_tip.py Outdated

from astroid.exceptions import InferenceOverwriteError
from astroid.nodes import NodeNG
from astroid import bases, nodes, util
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

There are some circular import in astroid, between files and between packages, I think importing only what's necessary and not whole package will help to understand what is happening in the code if we want to one day handle the issue.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

On the other hand, importing submodules avoid such import errors as we will get notified of those patterns sooner.

But I'll revert if you want me to!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@cdce8p do you have an opinion ? It's been a long time since I tried to fix those circular imports, all I remember is the pain 😄

Copy link
Copy Markdown
Member

@Pierre-Sassoulas Pierre-Sassoulas left a comment

Choose a reason for hiding this comment

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

Let's worry about circular import when they happen or when we fix them, thank you @DanielNoord

@Pierre-Sassoulas Pierre-Sassoulas merged commit 514c832 into pylint-dev:main Feb 21, 2022
@DanielNoord DanielNoord deleted the recursion branch February 21, 2022 19:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants