Open
Description
I was looking at the MR to fix context.clone
and noticed that I didn't really knew anymore what the current status is, which bugs exist, and which have been fixed.
Lets try to gather the information here. Ideally that will make reviewing and working on the remaining issues a lot easier.
/CC: @hippo91, @nelfin, @Pierre-Sassoulas
Original MR
Fix strong references to mutable objects in context.clone #927
Idea: Fix cycles in context.path
Fixes: #926
pylint
MR to update tests: pylint-dev/pylint#4325
Issues
unsupported-membership-test
=> Fixed
Reason:property
members defined on a metaclass were not inferred as data descriptors in a class context on derived classes (e.g.EnumMeta
->Enum
->ExampleEnum(Enum)
)
Ideas: related to brain_namedtuple_enum?
Open Issue: @property members defined in metaclasses of a base class are not correctly inferred #940
Open MR: Inferring property fields in a class context when metaclass is present #941
Status: Inferring property fields in a class context when metaclass is present #941 fixes the underlying issue, but in the specific case ofEnum
classes, the__members__
property reverts to being lUninferable
. This means thatunsupported-membership-test
will not be raised, but also any checks on the actual content of__members__
for subclass-Enum class definitions are not otherwise useful. I have a wip fix for brain_namedtuple_enum at https://github.com/nelfin/astroid/tree/fix/XXX-enum-class-members-brain but I hadn't progressed any further than that
@nelfin: I've updated Inferring property fields in a class context when metaclass is present #941 to fix the issue withEnum.__members__
and added a MR to pylint for the corresponding tests
Update regression tests for PyCQA/astroid#940 pylint#4466
Assigned: -
from enum import Enum
class MyEnum(Enum):
CONST1 = "const"
def name_in_enum(name):
# false-positive: unsupported-membership-test
if name in MyEnum.__members__:
return
not-callable
(1) => Fixed
Reason:delayed_assattr
allowed setting attributes on thebultins.object
class. Incorrect inference of a type in thecollections.OrderedDict.pop
method (imported bytyping
, hence some observations) meant thatobject.prev = None
andobject.next = None
had been "set". (see the sentinel__marker = object()
onOrderedDict
and its usage inpop
and__delitem__
)
Open Issue: Delayed attribute assignment to object() may cause incorrect inference of instance attributes #945
Open MR: Update _can_assign_attr to return False for builtins.object #946
Open MRpylint
: Add regression tests of instance attribute inference on builtins.object pylint#4348
Fixedpylint
issues: Regression with not-callable pylint#3595, not-callable: false positive due to conflit between "next" user-function and "collections.abc" pylint#3970, False positive E1102 when adding a non-callable attribute to object pylint#4221, False positive on E1102 (not-callable) for methods called prev or next pylint#4232
Status: Fixed
Assigned: @nelfin
class Example:
def func(self):
pass
whatthe = object()
whatthe.func = None
ex = Example()
ex.func() # false-positive: not-callable
not-callable
(2)
Not a regression with infer_stmts cannot infer multiple uses of the same AssignName #926 and Update _can_assign_attr to return False for builtins.object #946, that test case fails on current master without those changes.
Reason:data['abc']
is inferred asNone
. The reason seems to be that the name lookup does only find the initial assignment. Thus the change tolambda: ...
isn't know during the check. A fix would probably require changing theinfer_name
andlookup
methods.
Status: ?
Assigned: -
data = {
'abc': None,
}
data['abc'] = lambda: print("Callback called")
data['abc']() # false-positive `not-callable`
CONST = "my_constant"
invalid-sequence-index
Reason:instance_getitem
only returns the first call result. Since pylintsafe_infer
only sees one type it assumes that it can go ahead with theinvalid-sequence-index
check
Status: No fix yet, need to discuss. I assume that we should "fix"/updateinstance_getitem
to return all call results orUninferable
if there are multiple types? Shouldinstance_getitem
just returnmethod.infer_call_result(...)
instead ofnext(method.infer_call_result(...))
. Then pylint_check_sequence_index
should be updated to check that all inferred types are sequences (a lano-member
checking if any inferred type has that member)
Assigned: -
class DynamicGetitem:
def __getitem__(self, key):
if key == 'attributes':
return []
return {'world': 123}
ex = DynamicGetitem()
ex['hello']['world']
# E1126: Sequence index is not an int, slice, or instance with __index__ (invalid-sequence-index)
no-member
=> Fixed
Reason: Regression noticed after change in inference oftyping.Generic
Status: Fixed with Fix strong references to mutable objects in context.clone #927 and Update _can_assign_attr to return False for builtins.object #946
Open Issue: member lookup with Generic base class in 2.5.3 #942
MR for test cases: Add regression test for no-member with generic base class pylint#4471
Assigned: -
from abc import ABC
from typing import Generic, TypeVar
Anything = TypeVar("Anything")
MoreSpecific = TypeVar("MoreSpecific", str, int)
class A(ABC, Generic[Anything]):
def a_method(self) -> None:
print("hello")
class B(A[MoreSpecific]):
pass
class C(B[str]):
pass
c = C()
c.a_method() # false-positive: no-member
Related
pylint
MR with regression test cases (not yet fixed): Add regression tests for inference bug repros pylint#4387
PRs with fixed test cases
#992
pylint-dev/pylint#4325
pylint-dev/pylint#4348
pylint-dev/pylint#4471
pylint-dev/pylint#4473