1515#
1616# You should have received a copy of the GNU General Public License
1717# along with this program. If not, see <http://www.gnu.org/licenses/>.
18+ import columnize
1819import inspect
1920import os .path as osp
2021import re
@@ -90,15 +91,16 @@ def lineinfo(self, arg):
9091
9192 def run (self , args ):
9293 """Current line number in source file"""
93- if not self .proc .curframe :
94- self .errmsg ("No line number information available." )
95- return
96-
9794 # info line <loc>
9895 if len (args ) == 0 :
96+ if not self .proc .curframe :
97+ self .errmsg ("Frame is needed when no line number is given." )
98+ return
99+
99100 # No line number. Use current frame line number
100101 line_number = inspect .getlineno (self .proc .curframe )
101102 filename = self .core .canonic_filename (self .proc .curframe )
103+
102104 elif len (args ) == 1 :
103105 # lineinfo returns (item, file, lineno) or (None,)
104106 line_number , filename = self .lineinfo (args [2 :])
@@ -123,25 +125,21 @@ def run(self, args):
123125 return
124126 msg1 = 'Line %d of "%s"' % (line_number , self .core .filename (filename ),)
125127 line_info = linecache_info .line_info
126- if line_info :
127- msg2 = "is at offset(s) %s" % ", " .join (linecache_info .line_numbers [line_number ])
128- self .msg (wrapped_lines (msg1 , msg2 , self .settings ["width" ]))
128+ line_number_offsets = line_info .get (line_number )
129+ if line_number_offsets :
130+ offset_data = [f"{ code .co_name } :*{ offset } " for code , offset in line_number_offsets ]
131+ if len (offset_data ) == 1 :
132+ msg2 = f"is at bytecode offset { offset_data [0 ]} "
133+ self .msg (wrapped_lines (msg1 , msg2 , self .settings ["width" ]))
134+ else :
135+ msg2 = "is at bytecode offsets:"
136+ self .msg (wrapped_lines (msg1 , msg2 , self .settings ["width" ]))
137+ self .msg (columnize .columnize (offset_data , colsep = ", " , ljust = False , lineprefix = " " ))
129138 else :
130139 self .errmsg (
131140 "No line information for line %d of %s"
132141 % (line_number , self .core .filename (filename ))
133142 )
134- if line_info and len (line_info ) > 1 :
135- self .msg (
136- wrapped_lines (
137- "There are multiple line offsets for line number." ,
138- "Other line offsets: %s"
139- % ", " .join (
140- ["%s of %s" % (li .offsets [0 ], li .name ) for li in line_info [1 :]]
141- ),
142- self .settings ["width" ],
143- )
144- )
145143 return False
146144
147145 pass
0 commit comments