summaryrefslogtreecommitdiffstats
path: root/debian/patches/0007-python-311-support.patch
blob: be8c9f012cecd3e319193d681ffce6c45034f318 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
From 6238d9e8b78f5327f60bd1d2606a37f951a3cd9c Mon Sep 17 00:00:00 2001
From: Christoph Erhardt <github@sicherha.de>
Date: Wed, 22 Jun 2022 21:42:53 +0200
Subject: [PATCH] Ensure compatibility with Python 3.11

* Replace deprecated `getargspec()` with `getfullargspec()`
* Replace deprecated `formatargspec()` with custom implementation

Fixes #2209.
---
 docs/source/powerline_autodoc.py |  6 ++----
 powerline/lint/inspect.py        | 34 +++++++++++++++++++++++++++++---
 2 files changed, 33 insertions(+), 7 deletions(-)

diff --git a/docs/source/powerline_autodoc.py b/docs/source/powerline_autodoc.py
index eba42edb7..83996aeaf 100644
--- a/docs/source/powerline_autodoc.py
+++ b/docs/source/powerline_autodoc.py
@@ -3,11 +3,9 @@
 
 import os
 
-from inspect import formatargspec
-
 from sphinx.ext import autodoc
 
-from powerline.lint.inspect import getconfigargspec
+from powerline.lint.inspect import formatconfigargspec, getconfigargspec
 from powerline.segments import Segment
 from powerline.lib.unicode import unicode
 
@@ -28,7 +26,7 @@ def can_document_member(cls, member, membername, isattr, parent):
 
 	def format_args(self):
 		argspec = getconfigargspec(self.object)
-		return formatargspec(*argspec, formatvalue=formatvalue).replace('\\', '\\\\')
+		return formatconfigargspec(*argspec, formatvalue=formatvalue).replace('\\', '\\\\')
 
 
 class Repr(object):
diff --git a/powerline/lint/inspect.py b/powerline/lint/inspect.py
index 15bb6103b..7ab720f84 100644
--- a/powerline/lint/inspect.py
+++ b/powerline/lint/inspect.py
@@ -1,7 +1,8 @@
 # vim:fileencoding=utf-8:noet
 from __future__ import (unicode_literals, division, absolute_import, print_function)
 
-from inspect import ArgSpec, getargspec
+from inspect import FullArgSpec, getfullargspec
+from itertools import zip_longest
 
 from powerline.segments import Segment
 
@@ -33,7 +34,7 @@ def getconfigargspec(obj):
 	requires_filesystem_watcher = hasattr(obj, 'powerline_requires_filesystem_watcher')
 
 	for name, method in argspecobjs:
-		argspec = getargspec(method)
+		argspec = getfullargspec(method)
 		omitted_args = get_omitted_args(name, method)
 		largs = len(argspec.args)
 		for i, arg in enumerate(reversed(argspec.args)):
@@ -60,4 +61,31 @@ def getconfigargspec(obj):
 				if arg not in args:
 					args.insert(0, arg)
 
-	return ArgSpec(args=args, varargs=None, keywords=None, defaults=tuple(defaults))
+	return FullArgSpec(args=args, varargs=None, varkw=None, defaults=tuple(defaults), kwonlyargs=(), kwonlydefaults={}, annotations={})
+
+
+def formatconfigargspec(args, varargs=None, varkw=None, defaults=None,
+                        kwonlyargs=(), kwonlydefaults={}, annotations={},
+                        formatvalue=lambda value: '=' + repr(value)):
+	'''Format an argument spec from the values returned by getconfigargspec.
+
+	This is a specialized replacement for inspect.formatargspec, which has been
+	deprecated since Python 3.5 and was removed in Python 3.11. It supports
+	valid values for args, defaults and formatvalue; all other parameters are
+	expected to be either empty or None.
+	'''
+	assert varargs is None
+	assert varkw is None
+	assert not kwonlyargs
+	assert not kwonlydefaults
+	assert not annotations
+
+	specs = []
+	if defaults:
+		firstdefault = len(args) - len(defaults)
+	for i, arg in enumerate(args):
+		spec = arg
+		if defaults and i >= firstdefault:
+			spec += formatvalue(defaults[i - firstdefault])
+		specs.append(spec)
+	return '(' + ', '.join(specs) + ')'