diff options
| author | hippo91 <guillaume.peillex@gmail.com> | 2021-01-23 11:26:50 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-01-23 11:26:50 +0100 |
| commit | 869b851169150de2d9208741504d267a43a190ac (patch) | |
| tree | ca2138916a5ebb754937312ef852cff9a63ecbfc | |
| parent | c9fd1934e9c49d9052f64439fc7ea82026bce00f (diff) | |
| parent | 294623e1f1c4a83c193e6eb8c61cf1cb7233b8b9 (diff) | |
| download | astroid-git-869b851169150de2d9208741504d267a43a190ac.tar.gz | |
Merge pull request #882 from Polyconseil/dbaty/subprocess_popen_class_getitem
brain: Add `__class_getitem__` to `subprocess.Popen` starting from Python 3.9
| -rw-r--r-- | ChangeLog | 4 | ||||
| -rw-r--r-- | astroid/brain/brain_subprocess.py | 7 | ||||
| -rw-r--r-- | tests/unittest_brain.py | 7 |
3 files changed, 18 insertions, 0 deletions
@@ -7,6 +7,10 @@ What's New in astroid 2.5.0? ============================ Release Date: TBA +* Add ``__class_getitem__`` method to ``subprocess.Popen`` brain under Python 3.9 so that it is seen as subscriptable by pylint. + + Fixes PyCQA/pylint#4034 + * Adds `degrees`, `radians`, which are `numpy ufunc` functions, in the `numpy` brain. Adds `random` function in the `numpy.random` brain. Fixes PyCQA/pylint#3856 diff --git a/astroid/brain/brain_subprocess.py b/astroid/brain/brain_subprocess.py index bc35704f..c19b32b1 100644 --- a/astroid/brain/brain_subprocess.py +++ b/astroid/brain/brain_subprocess.py @@ -14,6 +14,7 @@ import textwrap import astroid +PY39 = sys.version_info >= (3, 9) PY37 = sys.version_info >= (3, 7) PY36 = sys.version_info >= (3, 6) @@ -147,6 +148,12 @@ def _subprocess_transform(): "py3_args": py3_args, } ) + if PY39: + code += """ + @classmethod + def __class_getitem__(cls, item): + pass + """ init_lines = textwrap.dedent(init).splitlines() indented_init = "\n".join(" " * 4 + line for line in init_lines) diff --git a/tests/unittest_brain.py b/tests/unittest_brain.py index 7bb1f70f..4717ab76 100644 --- a/tests/unittest_brain.py +++ b/tests/unittest_brain.py @@ -1292,6 +1292,13 @@ class SubprocessTest(unittest.TestCase): assert isinstance(inferred, astroid.Const) assert isinstance(inferred.value, (str, bytes)) + @test_utils.require_version("3.9") + def test_popen_does_not_have_class_getitem(self): + code = """import subprocess; subprocess.Popen""" + node = astroid.extract_node(code) + inferred = next(node.infer()) + assert "__class_getitem__" in inferred + class TestIsinstanceInference: """Test isinstance builtin inference""" |
