statprof: with Python 3.12, lineno is (more) often None stable
authorMads Kiilerich <mads@kiilerich.com>
Tue, 07 Mar 2023 17:13:38 +0100
branchstable
changeset 50305 972f3e5c94b8
parent 50304 805d4a462abb
child 50306 90276164333a
child 50436 c5e93c915ab6
statprof: with Python 3.12, lineno is (more) often None test-profile.t failed with errors like: TypeError: %d format: a real number is required, not NoneType statprof.py already handled None values as -1 in some cases. Do the same in more cases.
mercurial/statprof.py
--- a/mercurial/statprof.py	Tue Mar 07 16:45:54 2023 +0100
+++ b/mercurial/statprof.py	Tue Mar 07 17:13:38 2023 +0100
@@ -540,7 +540,11 @@
 
     for stat in stats:
         site = stat.site
-        sitelabel = b'%s:%d:%s' % (site.filename(), site.lineno, site.function)
+        sitelabel = b'%s:%d:%s' % (
+            site.filename(),
+            site.lineno or -1,
+            site.function,
+        )
         fp.write(
             b'%6.2f %9.2f %9.2f  %s\n'
             % (
@@ -613,7 +617,7 @@
                 stattuple = (
                     stat.selfpercent(),
                     stat.selfseconds(),
-                    stat.site.lineno,
+                    stat.site.lineno or -1,
                     source,
                 )