-
-
Notifications
You must be signed in to change notification settings - Fork 55
/
generate-six-info
executable file
·61 lines (50 loc) · 1.86 KB
/
generate-six-info
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
#!/usr/bin/env python3
from __future__ import annotations
import os.path
import sys
import six
def main() -> int:
# some special ones
removes = ['from six import callable', 'from six import next']
renames = []
for move in six._moved_attributes: # type: ignore
if isinstance(move, six.MovedAttribute):
if move.name != move.attr:
continue
if move.mod == 'builtins':
removes.append(f'from six.moves import {move.name}')
else:
renames.append(f'six.moves={move.mod}:{move.name}')
elif isinstance(move, six.MovedModule):
if f'six.moves.{move.name}' == move.mod:
renames.append(f'six.moves.{move.name}={move.name}')
else:
renames.append(f'six.moves.{move.name}={move.mod}')
else:
raise NotImplementedError(type(move))
# six.moves.urllib imports urllb.* which doesn't happen with
# `import urllib`
urllib_index = renames.index('six.moves.urllib=urllib')
renames[urllib_index:urllib_index + 1] = [
# but imports from submodules are fine
f'six.moves.urllib.{submod}=urllib.{submod}'
for submod in ('error', 'parse', 'request', 'response', 'robotparser')
]
# not in six.moves for some reason
renames.extend((
'six=functools:wraps',
'six=io:StringIO',
'six=io:BytesIO',
))
removes_s = ''.join(f' {r!r},\n' for r in sorted(removes))
renames_s = ''.join(f' {r!r},\n' for r in sorted(renames))
print(
f'# GENERATED VIA {os.path.basename(sys.argv[0])}\n'
f'# Using six=={six.__version__}\n'
f'REMOVALS[(3,)].update((\n{removes_s}))\n'
f'REPLACES[(3,)].update((\n{renames_s}))\n'
f'# END GENERATED\n',
)
return 0
if __name__ == '__main__':
raise SystemExit(main())