diff options
author | Pierre Sassoulas <pierre.sassoulas@gmail.com> | 2023-04-01 13:12:22 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-01 13:12:22 +0200 |
commit | 895c6d7e847eea78a11e832429cf4a06ace93647 (patch) | |
tree | c8527b35cc3328634b83f48f13cbe065d914cb5b /tests | |
parent | 1bc3e7603042363d1bc01f53ad6b5fe97ee18fc7 (diff) | |
download | astroid-git-895c6d7e847eea78a11e832429cf4a06ace93647.tar.gz |
Support attrs decorators even if they are imported from attrs (#2059) (#2073)
Use inference to determine membership of ``attr(s)`` module
Co-authored-by: Daniƫl van Noord <13665637+DanielNoord@users.noreply.github.com>
(cherry picked from commit 489c90fb29970d9362f21f26247bd45a39832dcd)
Co-authored-by: alm <alonme@users.noreply.github.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/brain/test_attr.py | 34 |
1 files changed, 32 insertions, 2 deletions
diff --git a/tests/brain/test_attr.py b/tests/brain/test_attr.py index d9a65f90..0648109e 100644 --- a/tests/brain/test_attr.py +++ b/tests/brain/test_attr.py @@ -90,7 +90,8 @@ class AttrsTest(unittest.TestCase): module = astroid.parse( """ import attrs - from attrs import field, mutable, frozen + from attrs import field, mutable, frozen, define + from attrs import mutable as my_mutable @attrs.define class Foo: @@ -141,10 +142,39 @@ class AttrsTest(unittest.TestCase): l = Eggs(d=1) l.d['answer'] = 42 + + + @frozen + class Legs: + d = attrs.field(default=attrs.Factory(dict)) + + m = Legs(d=1) + m.d['answer'] = 42 + + @define + class FooBar: + d = attrs.field(default=attrs.Factory(dict)) + + n = FooBar(d=1) + n.d['answer'] = 42 + + @mutable + class BarFoo: + d = attrs.field(default=attrs.Factory(dict)) + + o = BarFoo(d=1) + o.d['answer'] = 42 + + @my_mutable + class FooFoo: + d = attrs.field(default=attrs.Factory(dict)) + + p = FooFoo(d=1) + p.d['answer'] = 42 """ ) - for name in ("f", "g", "h", "i", "j", "k", "l"): + for name in ("f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p"): should_be_unknown = next(module.getattr(name)[0].infer()).getattr("d")[0] self.assertIsInstance(should_be_unknown, astroid.Unknown) |