Skip to content

brain_attrs: Support annotation-only members#2515

Merged
Pierre-Sassoulas merged 1 commit intopylint-dev:maintenance/3.3.xfrom
Hnasar:fix-attrs-no-member
Aug 27, 2024
Merged

brain_attrs: Support annotation-only members#2515
Pierre-Sassoulas merged 1 commit intopylint-dev:maintenance/3.3.xfrom
Hnasar:fix-attrs-no-member

Conversation

@Hnasar
Copy link
Contributor

@Hnasar Hnasar commented Aug 23, 2024

Similar to dataclasses, the following class which uses instance variable annotations is valid:

@attrs.define
class AttrsCls:
    x: int
AttrsCls(1).x

However, before this commit astroid failed to transform the class attribute into an instance attribute and this led to no-member errors in pylint.

Only the new attrs API supports this form out-of-the-box, so just address the common case.

Type of Changes

Type
🐛 Bug fix

Closes #2514

Similar to dataclasses, the following class which uses instance
variable annotations is valid:

```py
@attrs.define
class AttrsCls:
    x: int
AttrsCls(1).x
```

However, before this commit astroid failed to transform the class
attribute into an instance attribute and this led to `no-member` errors
in pylint.

Only the new `attrs` API supports this form out-of-the-box, so just
address the common case.

Closes pylint-dev#2514
@codecov
Copy link

codecov bot commented Aug 23, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Please upload report for BASE (maintenance/3.3.x@4ae4617). Learn more about missing BASE report.

Additional details and impacted files

Impacted file tree graph

@@                 Coverage Diff                  @@
##             maintenance/3.3.x    #2515   +/-   ##
====================================================
  Coverage                     ?   92.99%           
====================================================
  Files                        ?       93           
  Lines                        ?    11043           
  Branches                     ?        0           
====================================================
  Hits                         ?    10269           
  Misses                       ?      774           
  Partials                     ?        0           
Flag Coverage Δ
linux 92.86% <100.00%> (?)
pypy 92.99% <100.00%> (?)
windows 92.97% <100.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
astroid/brain/brain_attrs.py 100.00% <100.00%> (ø)
---- 🚨 Try these New Features:

@Hnasar
Copy link
Contributor Author

Hnasar commented Aug 27, 2024 via email

@Pierre-Sassoulas Pierre-Sassoulas merged commit 5eae215 into pylint-dev:maintenance/3.3.x Aug 27, 2024
@Pierre-Sassoulas
Copy link
Member

Thank you @Hnasar, clean PR !

@Hnasar Hnasar deleted the fix-attrs-no-member branch August 30, 2024 15:31
@jacobtylerwalls jacobtylerwalls added this to the 3.3.3 milestone Sep 19, 2024
@jacobtylerwalls
Copy link
Member

@Hnasar for your next contribution, could you always target main? If this qualifies for a backport, someone will let you know. In the meantime, could you prepare a pull request against main to ensure your contribution is not lost in astroid 3.4 or 4.0, whichever version is next?

@jacobtylerwalls
Copy link
Member

In the meantime, could you prepare a pull request against main to ensure your contribution is not lost in astroid 3.4

Never mind, this will be taken care of in our usual release process.

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.

4 participants