Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the __annotations__ attribute to the ClassDef object model. #2431

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mbyrnepr2
Copy link
Member

@mbyrnepr2 mbyrnepr2 commented May 12, 2024

Type of Changes

Type
βœ“ πŸ› Bug fix
✨ New feature
πŸ”¨ Refactoring
πŸ“œ Docs

Description

Add the __annotations__ attribute to the ClassDef object model.
Pylint now does not emit a no-member error when accessing __annotations__ in the following cases:

case 1.

class Test:
    print(__annotations__)

case 2.

from typing import TypedDict

OtherTypedDict = TypedDict('OtherTypedDict', {'a': int, 'b': str})
print(OtherTypedDict.__annotations__)

case 1 is similar to the behaviour of some of the other special attributes:

class Test:
    print(__module__)
    print(__qualname__)
    print(__annotations__)

It turns out that this fix also fixed case 2.
However, it's still unclear why case 2 was only a false positive for Python 3.9 and older 😬

Closes pylint-dev/pylint#7126

Pylint now does not emit a ``no-member`` error when accessing
``__annotations`` in the following cases:

```
class Test:
    print(__annotations__)
```

```
from typing import TypedDict

OtherTypedDict = TypedDict('OtherTypedDict', {'a': int, 'b': str})
print(OtherTypedDict.__annotations__)
```

Closes pylint-dev/pylint#7126
Copy link

codecov bot commented May 12, 2024

Codecov Report

All modified and coverable lines are covered by tests βœ…

Project coverage is 92.78%. Comparing base (2c38c02) to head (8876aa5).
Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #2431   +/-   ##
=======================================
  Coverage   92.78%   92.78%           
=======================================
  Files          94       94           
  Lines       11098    11101    +3     
=======================================
+ Hits        10297    10300    +3     
  Misses        801      801           
Flag Coverage Ξ”
linux 92.59% <100.00%> (+<0.01%) ⬆️
pypy 92.78% <100.00%> (+<0.01%) ⬆️
windows 92.68% <100.00%> (+<0.01%) ⬆️

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

Files Coverage Ξ”
astroid/interpreter/objectmodel.py 93.29% <100.00%> (+0.04%) ⬆️
astroid/nodes/scoped_nodes/scoped_nodes.py 92.52% <100.00%> (ΓΈ)

@mbyrnepr2 mbyrnepr2 marked this pull request as ready for review May 12, 2024 17:40
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.

False positive no-member for TypedDict.__annotations__
1 participant