From 1acdfec359fdf3db936168480be0f4157273c200 Mon Sep 17 00:00:00 2001 From: Batuhan Taskaya Date: Tue, 22 Nov 2022 13:41:14 +0300 Subject: gh-99341: Cover type ignore nodes when incrementing line numbers (GH-99422) --- Lib/ast.py | 6 ++++++ Lib/test/test_ast.py | 12 ++++++++++++ .../Library/2022-11-13-02-06-56.gh-issue-99341.8-OlwB.rst | 2 ++ 3 files changed, 20 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2022-11-13-02-06-56.gh-issue-99341.8-OlwB.rst diff --git a/Lib/ast.py b/Lib/ast.py index 1a94e93..2cbc80a 100644 --- a/Lib/ast.py +++ b/Lib/ast.py @@ -237,6 +237,12 @@ def increment_lineno(node, n=1): location in a file. """ for child in walk(node): + # TypeIgnore is a special case where lineno is not an attribute + # but rather a field of the node itself. + if isinstance(child, TypeIgnore): + child.lineno = getattr(child, 'lineno', 0) + n + continue + if 'lineno' in child._attributes: child.lineno = getattr(child, 'lineno', 0) + n if ( diff --git a/Lib/test/test_ast.py b/Lib/test/test_ast.py index b346441..773fba8 100644 --- a/Lib/test/test_ast.py +++ b/Lib/test/test_ast.py @@ -1036,6 +1036,18 @@ Module( self.assertEqual(ast.increment_lineno(src).lineno, 2) self.assertIsNone(ast.increment_lineno(src).end_lineno) + def test_increment_lineno_on_module(self): + src = ast.parse(dedent("""\ + a = 1 + b = 2 # type: ignore + c = 3 + d = 4 # type: ignore@tag + """), type_comments=True) + ast.increment_lineno(src, n=5) + self.assertEqual(src.type_ignores[0].lineno, 7) + self.assertEqual(src.type_ignores[1].lineno, 9) + self.assertEqual(src.type_ignores[1].tag, '@tag') + def test_iter_fields(self): node = ast.parse('foo()', mode='eval') d = dict(ast.iter_fields(node.body)) diff --git a/Misc/NEWS.d/next/Library/2022-11-13-02-06-56.gh-issue-99341.8-OlwB.rst b/Misc/NEWS.d/next/Library/2022-11-13-02-06-56.gh-issue-99341.8-OlwB.rst new file mode 100644 index 0000000..451561c --- /dev/null +++ b/Misc/NEWS.d/next/Library/2022-11-13-02-06-56.gh-issue-99341.8-OlwB.rst @@ -0,0 +1,2 @@ +Fix :func:`ast.increment_lineno` to also cover :class:`ast.TypeIgnore` when +changing line numbers. -- cgit v0.12 t/Qt.git/diff/doc/src/snippets/code/src_sql_models_qsqlquerymodel.cpp?id=03baad51d584778a99f4b393232ccc1312db3391'>diffstats
path: root/doc/src/snippets/code/src_sql_models_qsqlquerymodel.cpp
blob: 71049d28e333856e76a5c94cc26b389492fb6f3c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/****************************************************************************
**
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the documentation of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights.  These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**
**
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/

//! [0]
while (myModel->canFetchMore())
    myModel->fetchMore();
//! [0]


//! [1]
QSqlQueryModel model;
model.setQuery("select * from MyTable");
if (model.lastError().isValid())
    qDebug() << model.lastError();
//! [1]