Skip to content

Commit 1368be1

Browse files
Merge pull request #2570 from pylint-dev/post-3.3.3
Post 3.3.3
2 parents 5a93a9f + 11db16d commit 1368be1

File tree

5 files changed

+58
-6
lines changed

5 files changed

+58
-6
lines changed

CONTRIBUTORS.txt

+1
Original file line numberDiff line numberDiff line change
@@ -209,3 +209,4 @@ under this name, or we did not manage to find their commits in the history.
209209
- correctmost <[email protected]>
210210
- Oleh Prypin <[email protected]>
211211
- Eric Vergnaud <[email protected]>
212+
- Hashem Nasarat <[email protected]>

ChangeLog

+14-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Release date: TBA
99

1010

1111

12-
What's New in astroid 3.3.3?
12+
What's New in astroid 3.3.4?
1313
============================
1414
Release date: TBA
1515

@@ -18,6 +18,19 @@ Release date: TBA
1818
Closes pylint-dev/pylint#9811
1919

2020

21+
What's New in astroid 3.3.3?
22+
============================
23+
Release date: 2024-09-20
24+
25+
* Fix inference regression with property setters.
26+
27+
Closes pylint-dev/pylint#9811
28+
29+
* Add annotation-only instance attributes to attrs classes to fix `no-member` false positives.
30+
31+
Closes #2514
32+
33+
2134
What's New in astroid 3.3.2?
2235
============================
2336
Release date: 2024-08-11

astroid/brain/brain_attrs.py

+10-4
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@
2424
"field",
2525
)
2626
)
27+
NEW_ATTRS_NAMES = frozenset(
28+
(
29+
"attrs.define",
30+
"attrs.mutable",
31+
"attrs.frozen",
32+
)
33+
)
2734
ATTRS_NAMES = frozenset(
2835
(
2936
"attr.s",
@@ -33,9 +40,7 @@
3340
"attr.define",
3441
"attr.mutable",
3542
"attr.frozen",
36-
"attrs.define",
37-
"attrs.mutable",
38-
"attrs.frozen",
43+
*NEW_ATTRS_NAMES,
3944
)
4045
)
4146

@@ -64,13 +69,14 @@ def attr_attributes_transform(node: ClassDef) -> None:
6469
# Prevents https://github.com/pylint-dev/pylint/issues/1884
6570
node.locals["__attrs_attrs__"] = [Unknown(parent=node)]
6671

72+
use_bare_annotations = is_decorated_with_attrs(node, NEW_ATTRS_NAMES)
6773
for cdef_body_node in node.body:
6874
if not isinstance(cdef_body_node, (Assign, AnnAssign)):
6975
continue
7076
if isinstance(cdef_body_node.value, Call):
7177
if cdef_body_node.value.func.as_string() not in ATTRIB_NAMES:
7278
continue
73-
else:
79+
elif not use_bare_annotations:
7480
continue
7581
targets = (
7682
cdef_body_node.targets

script/.contributors_aliases.json

+4
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@
2222
2323
"name": "James Addison"
2424
},
25+
26+
27+
"name": "Hashem Nasarat"
28+
},
2529
2630
"mails": ["[email protected]"],
2731
"name": "Adam Hendry"

tests/brain/test_attr.py

+29-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import unittest
88

99
import astroid
10-
from astroid import nodes
10+
from astroid import exceptions, nodes
1111

1212
try:
1313
import attr # type: ignore[import] # pylint: disable=unused-import
@@ -201,3 +201,31 @@ class Foo:
201201
"""
202202
should_be_unknown = next(astroid.extract_node(code).infer()).getattr("bar")[0]
203203
self.assertIsInstance(should_be_unknown, astroid.Unknown)
204+
205+
def test_attr_with_only_annotation_fails(self) -> None:
206+
code = """
207+
import attr
208+
209+
@attr.s
210+
class Foo:
211+
bar: int
212+
Foo()
213+
"""
214+
with self.assertRaises(exceptions.AttributeInferenceError):
215+
next(astroid.extract_node(code).infer()).getattr("bar")
216+
217+
def test_attrs_with_only_annotation_works(self) -> None:
218+
code = """
219+
import attrs
220+
221+
@attrs.define
222+
class Foo:
223+
bar: int
224+
baz: str = "hello"
225+
Foo(1)
226+
"""
227+
for attr_name in ("bar", "baz"):
228+
should_be_unknown = next(astroid.extract_node(code).infer()).getattr(
229+
attr_name
230+
)[0]
231+
self.assertIsInstance(should_be_unknown, astroid.Unknown)

0 commit comments

Comments
 (0)