pylint-dev / pylint-dev/astroid
Type of enum value being incorrectly inferred
- Dominant language
- Python
- Stars
- 582
- Forks
- 357
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 23
Description
**Note**: this content is roughly equivalent to that of an still unanswered [question I posted at SO](https://stackoverflow.com/questions/59829094/incorrect-inference-of-enum-values-type-with-astroid-the-engine-behind-py).
``` py
from enum import Enum
class Whatever(Enum):
Foo = 1
Bar = 2
def f():
x = Whatever.Foo
```
Consider the program above an a call to `infer()` on expression `Whatever.Foo`.
### Current behavior
I get a (proxied) `ClassDef` for a `Foo` "type".
### Expected behavior
I'd expect a (proxied) `ClassDef` for `Whatever`.
This would be according to the [language specification](https://docs.python.org/3/library/enum.html#creating-an-enum), that says that *the type of an enumeration member is the enumeration it belongs to.*
astroid version: 2.3.3
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by reproducing the supplied Enum example with astroid 2.3.3 and inspect inference for the Whatever.Foo expression. Compare the current proxied ClassDef for Foo with the expected proxied ClassDef for Whatever; done means enum-member inference reports the containing enum type.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100