Skip to content

Commit

Permalink
Python 3.11 compatibility
Browse files Browse the repository at this point in the history
This patch adds the new arguments to the types.CodeType class
constructor in the clonefunc function.

See ionelmc#231
  • Loading branch information
danigm committed Jan 17, 2023
1 parent 7ef2645 commit b2f624a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/pytest_benchmark/compat.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import sys

PY38 = sys.version_info[0] == 3 and sys.version_info[1] >= 8
PY311 = sys.version_info[0] == 3 and sys.version_info[1] >= 11
6 changes: 5 additions & 1 deletion src/pytest_benchmark/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

import genericpath

from .compat import PY38
from .compat import PY38, PY311

# This is here (in the utils module) because it might be used by
# various other modules.
Expand Down Expand Up @@ -521,6 +521,10 @@ def clonefunc(f):
co.co_firstlineno, co.co_lnotab, co.co_freevars, co.co_cellvars]
if PY38:
args.insert(1, co.co_posonlyargcount)

if PY311:
args.insert(12, co.co_qualname)
args.insert(15, co.co_exceptiontable)
co2 = types.CodeType(*args)
#
# then, we clone the function itself, using the new co2
Expand Down

0 comments on commit b2f624a

Please sign in to comment.