[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v3 03/15] qapi/source: Remove line number from QAPISourceInfo ini
From: |
John Snow |
Subject: |
[PATCH v3 03/15] qapi/source: Remove line number from QAPISourceInfo initializer |
Date: |
Wed, 19 May 2021 14:39:39 -0400 |
With the QAPISourceInfo(None, None, None) construct gone, there's no
longer any reason to have to specify that a file starts on the first
line. Remove it from the initializer and default it to 1.
Remove the last vestiges where we check for 'line' being unset, that
can't happen, now.
Signed-off-by: John Snow <jsnow@redhat.com>
---
scripts/qapi/parser.py | 2 +-
scripts/qapi/source.py | 10 +++-------
2 files changed, 4 insertions(+), 8 deletions(-)
diff --git a/scripts/qapi/parser.py b/scripts/qapi/parser.py
index a53b735e7de..39dbcc4eacc 100644
--- a/scripts/qapi/parser.py
+++ b/scripts/qapi/parser.py
@@ -47,7 +47,7 @@ def __init__(self, fname, previously_included=None,
incl_info=None):
if self.src == '' or self.src[-1] != '\n':
self.src += '\n'
self.cursor = 0
- self.info = QAPISourceInfo(fname, 1, incl_info)
+ self.info = QAPISourceInfo(fname, incl_info)
self.line_pos = 0
self.exprs = []
self.docs = []
diff --git a/scripts/qapi/source.py b/scripts/qapi/source.py
index 1ade864d7b9..04193cc9643 100644
--- a/scripts/qapi/source.py
+++ b/scripts/qapi/source.py
@@ -31,10 +31,9 @@ def __init__(self) -> None:
class QAPISourceInfo:
T = TypeVar('T', bound='QAPISourceInfo')
- def __init__(self, fname: str, line: int,
- parent: Optional['QAPISourceInfo']):
+ def __init__(self, fname: str, parent: Optional['QAPISourceInfo']):
self.fname = fname
- self.line = line
+ self.line = 1
self.parent = parent
self.pragma: QAPISchemaPragma = (
parent.pragma if parent else QAPISchemaPragma()
@@ -52,10 +51,7 @@ def next_line(self: T) -> T:
return info
def loc(self) -> str:
- ret = self.fname
- if self.line is not None:
- ret += ':%d' % self.line
- return ret
+ return f"{self.fname}:{self.line}"
def in_defn(self) -> str:
if self.defn_name:
--
2.30.2
- [PATCH v3 00/15] qapi: static typing conversion, pt5a, John Snow, 2021/05/19
- [PATCH v3 05/15] qapi/parser: Assert lexer value is a string, John Snow, 2021/05/19
- [PATCH v3 01/15] qapi/parser: Don't try to handle file errors, John Snow, 2021/05/19
- [PATCH v3 07/15] qapi/parser: assert object keys are strings, John Snow, 2021/05/19
- [PATCH v3 15/15] qapi/parser: add docstrings, John Snow, 2021/05/19
- [PATCH v3 02/15] qapi: Add test for nonexistent schema file, John Snow, 2021/05/19
- [PATCH v3 04/15] qapi/parser: factor parsing routine into method, John Snow, 2021/05/19
- [PATCH v3 03/15] qapi/source: Remove line number from QAPISourceInfo initializer,
John Snow <=
- [PATCH v3 11/15] qapi/parser: Rework _check_pragma_list_of_str as a TypeGuard, John Snow, 2021/05/19
- [PATCH v3 10/15] qapi/parser: Fix token membership tests when token can be None, John Snow, 2021/05/19
- [PATCH v3 14/15] qapi/parser: allow 'ch' variable name, John Snow, 2021/05/19
- [PATCH v3 09/15] qapi: add must_match helper, John Snow, 2021/05/19
- [PATCH v3 08/15] qapi/parser: Use @staticmethod where appropriate, John Snow, 2021/05/19
- [PATCH v3 06/15] qapi/parser: enforce all top-level expressions must be dict in _parse(), John Snow, 2021/05/19
- [PATCH v3 12/15] qapi/parser: add type hint annotations, John Snow, 2021/05/19
- [PATCH v3 13/15] qapi/parser: Remove superfluous list comprehension, John Snow, 2021/05/19