From 584b1fdb7bb5d4ccd631b9216be89d9adad490bf Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Tue, 26 Sep 2023 08:18:10 -0400 Subject: [PATCH 1/5] False positive ``unsubscriptable-object`` (#2307) (#2309) Fix a regression in 2.15.7 for ``unsubscriptable-object``. Raise an `InferenceError` when there is a `SyntaxError` due to an invalid `TypeVar` name. This reverts commit 89dfb4857670a67920d0f3ab88857d697787901d. Closes #2305 Closes pylint-dev/pylint#9069 (cherry picked from commit 1f0f2f8f780c3b639307a5f326b3963fdd6fa160) Co-authored-by: Mark Byrne <31762852+mbyrnepr2@users.noreply.github.com> --- ChangeLog | 10 ++++++++++ astroid/brain/brain_typing.py | 13 +++++-------- tests/brain/test_typing.py | 15 ++++++++------- 3 files changed, 23 insertions(+), 15 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5c003823e7..a2fbf85f10 100644 --- a/ChangeLog +++ b/ChangeLog @@ -7,6 +7,16 @@ What's New in astroid 2.15.8? Release date: TBA +What's New in astroid 2.15.8? +============================= +Release date: TBA + +* Fix a regression in 2.15.7 for ``unsubscriptable-object``. + + Closes #2305 + Closes pylint-dev/pylint#9069 + + What's New in astroid 2.15.7? ============================= Release date: 2023-09-23 diff --git a/astroid/brain/brain_typing.py b/astroid/brain/brain_typing.py index 2cd5a32893..564396c4ca 100644 --- a/astroid/brain/brain_typing.py +++ b/astroid/brain/brain_typing.py @@ -15,6 +15,7 @@ from astroid.builder import _extract_single_node from astroid.const import PY38_PLUS, PY39_PLUS from astroid.exceptions import ( + AstroidSyntaxError, AttributeInferenceError, InferenceError, UseInferenceDefault, @@ -139,14 +140,10 @@ def infer_typing_typevar_or_newtype( raise UseInferenceDefault typename = node.args[0].as_string().strip("'") - node = ClassDef( - name=typename, - lineno=node.lineno, - col_offset=node.col_offset, - parent=node.parent, - end_lineno=node.end_lineno, - end_col_offset=node.end_col_offset, - ) + try: + node = extract_node(TYPING_TYPE_TEMPLATE.format(typename)) + except AstroidSyntaxError as exc: + raise InferenceError from exc return node.infer(context=context_itton) diff --git a/tests/brain/test_typing.py b/tests/brain/test_typing.py index 4fdff77ae9..f8b47cc2ef 100644 --- a/tests/brain/test_typing.py +++ b/tests/brain/test_typing.py @@ -5,7 +5,10 @@ # For details: https://github.com/pylint-dev/astroid/blob/main/LICENSE # Copyright (c) https://github.com/pylint-dev/astroid/blob/main/CONTRIBUTORS.txt -from astroid import builder, nodes +import pytest + +from astroid import builder +from astroid.exceptions import InferenceError def test_infer_typevar() -> None: @@ -15,13 +18,11 @@ def test_infer_typevar() -> None: Test that an inferred `typing.TypeVar()` call produces a `nodes.ClassDef` node. """ - assign_node = builder.extract_node( + call_node = builder.extract_node( """ from typing import TypeVar - MyType = TypeVar('My.Type') + TypeVar('My.Type') """ ) - call = assign_node.value - inferred = next(call.infer()) - assert isinstance(inferred, nodes.ClassDef) - assert inferred.name == "My.Type" + with pytest.raises(InferenceError): + call_node.inferred() From c633af204678a69708857af0793b2a4ca11107b0 Mon Sep 17 00:00:00 2001 From: Jacob Walls Date: Tue, 26 Sep 2023 08:23:16 -0400 Subject: [PATCH 2/5] Bump astroid to 2.15.8, update changelog --- ChangeLog | 7 +------ astroid/__pkginfo__.py | 2 +- tbump.toml | 2 +- 3 files changed, 3 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index a2fbf85f10..89e2fc50d9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4,12 +4,7 @@ astroid's ChangeLog What's New in astroid 2.15.8? ============================= -Release date: TBA - - -What's New in astroid 2.15.8? -============================= -Release date: TBA +Release date: 2023-09-26 * Fix a regression in 2.15.7 for ``unsubscriptable-object``. diff --git a/astroid/__pkginfo__.py b/astroid/__pkginfo__.py index 9244a941c6..7d48031630 100644 --- a/astroid/__pkginfo__.py +++ b/astroid/__pkginfo__.py @@ -2,5 +2,5 @@ # For details: https://github.com/PyCQA/astroid/blob/main/LICENSE # Copyright (c) https://github.com/PyCQA/astroid/blob/main/CONTRIBUTORS.txt -__version__ = "2.15.7" +__version__ = "2.15.8" version = __version__ diff --git a/tbump.toml b/tbump.toml index fd1ad18098..e724658884 100644 --- a/tbump.toml +++ b/tbump.toml @@ -1,7 +1,7 @@ github_url = "https://github.com/PyCQA/astroid" [version] -current = "2.15.7" +current = "2.15.8" regex = ''' ^(?P0|[1-9]\d*) \. From d637bdff2b0a9b9d4fc691f8834310460288a608 Mon Sep 17 00:00:00 2001 From: Pierre Sassoulas Date: Mon, 25 Sep 2023 15:34:45 +0200 Subject: [PATCH 3/5] Revert "Add boilerplate for documenting an upgrade guide (#1873)" This reverts commit e3169329d3cd175d50a0eea2439dd4f7df4f46aa. --- doc/upgrade_guide.rst | 11 ----------- doc/whatsnew.rst | 1 - 2 files changed, 12 deletions(-) delete mode 100644 doc/upgrade_guide.rst diff --git a/doc/upgrade_guide.rst b/doc/upgrade_guide.rst deleted file mode 100644 index 79c57496fc..0000000000 --- a/doc/upgrade_guide.rst +++ /dev/null @@ -1,11 +0,0 @@ -=============== -Upgrade guide -=============== - -To ease the transition between major releases, the following page describes some of the breaking -changes between major release and what to change to safely upgrade. - -Upgrading from ``astroid`` ``2.x`` to ``3.0`` ---------------------------------------------- - -- Work in progress diff --git a/doc/whatsnew.rst b/doc/whatsnew.rst index b30ebc4fbd..e26a3c7b59 100644 --- a/doc/whatsnew.rst +++ b/doc/whatsnew.rst @@ -8,5 +8,4 @@ The "Changelog" contains *all* nontrivial changes to astroid for the current ver .. toctree:: :maxdepth: 2 - upgrade_guide changelog From 2891dafec472aa0ce7939c984965b345f7052036 Mon Sep 17 00:00:00 2001 From: Pierre Sassoulas Date: Mon, 25 Sep 2023 09:25:03 +0200 Subject: [PATCH 4/5] Bump astroid to 3.0.0, update changelog --- ChangeLog | 31 ++++++++++++++++++++++--------- astroid/__pkginfo__.py | 2 +- tbump.toml | 2 +- 3 files changed, 24 insertions(+), 11 deletions(-) diff --git a/ChangeLog b/ChangeLog index 49570217cb..d363f4b606 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,9 +2,22 @@ astroid's ChangeLog =================== + +What's New in astroid 3.1.0? +============================ +Release date: TBA + + + +What's New in astroid 3.0.1? +============================ +Release date: TBA + + + What's New in astroid 3.0.0? ============================= -Release date: TBA +Release date: 2023-09-25 * Add support for Python 3.12, including PEP 695 type parameter syntax. @@ -14,6 +27,14 @@ Release date: TBA Refs #2137 +* Use the global inference cache when inferring, even without an explicit + ``InferenceContext``. This is a significant performance improvement given how + often methods default to ``None`` for the context argument. (Linting ``astroid`` + itself now takes ~5% less time on Python 3.12; other projects requiring more + complex inference calculations will see greater speedups.) + + Refs #529 + * Following a deprecation period starting in astroid 2.7.0, the ``astroid.node_classes`` and ``astroid.scoped_nodes`` modules have been removed in favor of ``astroid.nodes.node_classes`` and ``astroid.nodes.scoped_nodes``. @@ -72,14 +93,6 @@ Release date: TBA Closes pylint-dev/pylint#7464 Closes pylint-dev/pylint#8074 -* Use the global inference cache when inferring, even without an explicit - ``InferenceContext``. This is a significant performance improvement given how - often methods default to ``None`` for the context argument. (Linting ``astroid`` - itself now takes ~5% less time on Python 3.12; other projects requiring more - complex inference calculations will see greater speedups.) - - Refs #529 - * Fix interrupted ``InferenceContext`` call chains, thereby addressing performance problems when linting ``sqlalchemy``. diff --git a/astroid/__pkginfo__.py b/astroid/__pkginfo__.py index 3373449a2e..6c2707620b 100644 --- a/astroid/__pkginfo__.py +++ b/astroid/__pkginfo__.py @@ -2,5 +2,5 @@ # For details: https://github.com/pylint-dev/astroid/blob/main/LICENSE # Copyright (c) https://github.com/pylint-dev/astroid/blob/main/CONTRIBUTORS.txt -__version__ = "3.0.0b1-dev0" +__version__ = "3.0.0" version = __version__ diff --git a/tbump.toml b/tbump.toml index 9662dc3614..35cebfe3e0 100644 --- a/tbump.toml +++ b/tbump.toml @@ -1,7 +1,7 @@ github_url = "https://github.com/pylint-dev/astroid" [version] -current = "3.0.0b1-dev0" +current = "3.0.0" regex = ''' ^(?P0|[1-9]\d*) \. From 0ea6d864c55d2841bd909232806ddf406fd1803b Mon Sep 17 00:00:00 2001 From: Pierre Sassoulas Date: Tue, 26 Sep 2023 15:14:50 +0200 Subject: [PATCH 5/5] Bump astroid to 3.1.0-dev0, update changelog --- astroid/__pkginfo__.py | 2 +- tbump.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/astroid/__pkginfo__.py b/astroid/__pkginfo__.py index 6c2707620b..ee9bd2e9d2 100644 --- a/astroid/__pkginfo__.py +++ b/astroid/__pkginfo__.py @@ -2,5 +2,5 @@ # For details: https://github.com/pylint-dev/astroid/blob/main/LICENSE # Copyright (c) https://github.com/pylint-dev/astroid/blob/main/CONTRIBUTORS.txt -__version__ = "3.0.0" +__version__ = "3.1.0-dev0" version = __version__ diff --git a/tbump.toml b/tbump.toml index 35cebfe3e0..6e61fd6b19 100644 --- a/tbump.toml +++ b/tbump.toml @@ -1,7 +1,7 @@ github_url = "https://github.com/pylint-dev/astroid" [version] -current = "3.0.0" +current = "3.1.0-dev0" regex = ''' ^(?P0|[1-9]\d*) \.