pylint-dev/astroid

`max_inferable_values` is only tunable on the class

LucasLeRay opened this issue · 3 comments

Steps to reproduce

Set MANAGER.max_inferable_values to any arbitrary number:

astroid.MANAGER.max_inferable_values = 1_000

Current behavior

the limit defined in NodeNG.infer will still be the default limit (100).
It comes from the fact that limit is defined by AstroidManager.max_inferable_values (the class) and not the MANAGER instance, like it was in 2.0.0:

class NodeNG:
    ...
    def infer(...):
        ...
        limit = AstroidManager.max_inferable_values  # 100
        ...

Expected behavior

Since 2.0.0 the limit should be tunable:

"Limit the maximum amount of interable result in an NodeNG.infer() call to 100 by default for performance issues with variables with large amounts of possible values. The max inferable value can be tuned by setting the max_inferable_values flag on astroid.MANAGER."

I saw no update in the changelog regarding this, so the limit should be 1_000 in my case, not 100.

python -c "from astroid import __pkginfo__; print(__pkginfo__.version)" output

3.0.0a9
(I also tried with 2.15.6)

Hi thanks, for the report.

Regarding v. 2.0, even then the AstroidManager was already documented as a singleton/borg, so it was already acting like a wrapper for class constants. Do you have an example of code that worked on 2.0 by manipulating instance attributes that doesn't work on 3.0.0a9?

In 2.0, the instance of an AstroidManager used to get the limit is a module constant. Without seeing a reproducer in more detail, it's hard to see where your expectations are being violated. Any more concrete info you can provide will be appreciated.

Thanks for your answer.

Indeed, thanks to your comment, I better understand what was done in 2.0.0.

I have no example of this working with 2.0.0, I only referred to the documentation to show that it should be possible to tune the max_inferable_values by setting a flag on astroid.MANAGER.

So, in my case, I want to be able to change the value of max_inferable_values used in NodeNG.infer.
But, from my current understanding, max_inferable_values was (and is) not tunable by the user, is that right?

It should be tunable if you set the class variable, as opposed to the (nonexistent) instance variable. (astroid.MANAGER is an instance, astroid.manager.AstroidManager is a class).

We can improve this situation though by creating instance properties that set the class properties like #2204. I'll make a PR.