pylint-dev / pylint-dev/astroid

re.compile inference returns incorrect result

Open
#520 1 comment 0 reactions 0 assignees View on GitHub
Bug 🪳
Dominant language
Python
Stars
582
Forks
357
Avg merge
1d 1h
Merged PRs (30d)
23

Description

### Steps to reproduce
1. Execute
```
import astroid
code = """
import re
_ENCODING_RGX = re.compile(r"f")
_ENCODING_RGX #@
"""
print(astroid.extract_node(code).inferred())
```

This is causing the Travis CI pylint env to fail with:
```
************* Module astroid.builder
E: 64,20: Instance of 'str' has no 'match' member (no-member)
```

### Current behavior

The above prints `[Uninferable, ]`

### Expected behavior

Should return an `Instance of _sre.SRE_Pattern`

### ``python -c "from astroid import __pkginfo__; print(__pkginfo__.version)"`` output

5d21b2005b06e3a353dd64aa16c6db5628058ed8

Contributor guide

No contributing guide indexed for this repository

Research direction

Reproduce the result with the provided astroid.extract_node example and inspect the astroid.builder location reported by pylint. Trace how re.compile is inferred and compare the result with the expected _sre.SRE_Pattern instance. Done means the example infers the compiled pattern rather than returning a string constant or Uninferable.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.