Closed Bug 1839263 Opened 2 years ago Closed 2 years ago

E TypeError: code expected at least 16 arguments, got 14

Categories

(Firefox Build System :: General, defect)

defect

Tracking

(firefox-esr115 fixed, firefox116 fixed)

RESOLVED FIXED
116 Branch
Tracking Status
firefox-esr115 --- fixed
firefox116 --- fixed

People

(Reporter: glandium, Assigned: glandium)

References

Details

Attachments

(2 files)

Running python/mozbuild/mozbuild/test/configure/test_lint.py locally fails with python 3.11 with e.g.:

 0:01.17 ________________________ TestLint.test_default_disable _________________________
 0:01.17 python/mozbuild/mozbuild/test/configure/test_lint.py:346: in test_default_disable
 0:01.17     self.lint_test()
 0:01.17 python/mozbuild/mozbuild/test/configure/test_lint.py:26: in lint_test
 0:01.17     sandbox.run(mozpath.join(test_data_path, "moz.configure"))
 0:01.17 python/mozbuild/mozbuild/configure/lint.py:44: in run
 0:01.17     self.include_file(path)
 0:01.17 python/mozbuild/mozbuild/configure/__init__.py:495: in include_file
 0:01.17     exec_(code, self)
 0:01.17 python/mozbuild/mozbuild/util.py:56: in exec_
 0:01.17     exec(object, globals, locals)
 0:01.17 python/mozbuild/mozbuild/test/configure/data/moz.configure:2: in <module>
 0:01.17     ???
 0:01.17 python/mozbuild/mozbuild/configure/lint.py:214: in option_impl
 0:01.17     self._check_option(result, *args, **kwargs)
 0:01.17 python/mozbuild/mozbuild/configure/lint.py:224: in _check_option
 0:01.17     self._check_prefix_for_bool_option(*args, **kwargs)
 0:01.17 python/mozbuild/mozbuild/configure/lint.py:259: in _check_prefix_for_bool_option
 0:01.17     self._raise_from(e, frame.f_back if frame else None)
 0:01.17 python/mozbuild/mozbuild/configure/lint.py:113: in _raise_from
 0:01.17     code = types.CodeType(*codetype_args)
 0:01.17 E   TypeError: code expected at least 16 arguments, got 14

Past that error, we also hit:

 0:02.32 During handling of the above exception, another exception occurred:
 0:02.32 python/mozbuild/mozbuild/test/configure/test_lint.py:340: in test_default_disable
 0:02.32     with self.assertRaisesFromLine(ConfigureError, 2) as e:
 0:02.32 /usr/lib/python3.11/contextlib.py:155: in __exit__
 0:02.32     self.gen.throw(typ, value, traceback)
 0:02.32 python/mozbuild/mozbuild/test/configure/test_lint.py:40: in assertRaisesFromLine
 0:02.32     traceback.extract_tb(tb)[-1][:2],
 0:02.32 E   IndexError: list index out of range

Python 3.10 added some more arguments to the CodeTypes constructor. It
also changed co_lnotab to co_linetables.

We were using co_lnotab to simulate a function with a def at a specific
line and a raise at a specific other line. I'm not sure how I ended up
with this particular requirement (this may have been related to python 2
still being used back then), but as of now, it doesn't seem we need the
def to be at a specific location, so we can avoid needing to generate
a co_linetables/co_lnotab, relying instead on the raise expression being
on the co_firstlineno+1 in the thrower function.

As for the extra arguments, it turns out python 3.8 also introduced a
CodeType.replace method that can be used to derive a CodeType object
from another, which is certainly simpler than calling its construtor
with the right set of arguments.

In python 3.11 (maybe also 3.10, I haven't tested that version ; 3.9 was
definitely different), by the time the context manager comes back in our
assertRaisesFromLine, the traceback is not available anymore (or yet,
I'm not entirely sure which way it does) to inspect and check the line
numbers we want to check.

And while assertRaises exposes the thrown exception in its exception
attribute, it also resets the traceback associated with it, so we can't
find it there either.

So instead, we implement our own context manager for
assertRaisesFromLine such that we can access that traceback.

Pushed by mh@glandium.org: https://hg.mozilla.org/integration/autoland/rev/ff226d67527a Fix python configure lint on python >= 3.10. r=firefox-build-system-reviewers,ahochheiden,sergesanspaille https://hg.mozilla.org/integration/autoland/rev/9ca24dcf06d7 Don't derive assertRaisesFromLine from assertRaises. r=firefox-build-system-reviewers,ahochheiden
Status: NEW → RESOLVED
Closed: 2 years ago
Resolution: --- → FIXED
Target Milestone: --- → 116 Branch
Duplicate of this bug: 1889124
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: