qapi/source: Remove line number from QAPISourceInfo initializer
authorJohn Snow <jsnow@redhat.com>
Wed, 19 May 2021 18:39:39 +0000 (14:39 -0400)
committerMarkus Armbruster <armbru@redhat.com>
Thu, 20 May 2021 09:28:27 +0000 (11:28 +0200)
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>
Message-Id: <20210519183951.3946870-4-jsnow@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
scripts/qapi/parser.py
scripts/qapi/source.py

index a53b735e7de04fe0c7a9a653828cb9026accda8c..39dbcc4eacc71fe91b69369885f12bb420ff4772 100644 (file)
@@ -47,7 +47,7 @@ class QAPISchemaParser:
         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 = []
index 1ade864d7b9d14cd88d0c60c066c5ddaf45c6845..04193cc964371aaba56cde9bb289b0b538c63e6a 100644 (file)
@@ -31,10 +31,9 @@ class QAPISchemaPragma:
 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 @@ class QAPISourceInfo:
         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: