python-minifier 3.3.0__py3-none-any.whl → 3.4.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- python_minifier/expression_printer.py +9 -3
- python_minifier/module_printer.py +5 -0
- python_minifier/rename/mapper.py +3 -1
- python_minifier/token_printer.py +2 -2
- python_minifier/transforms/combine_imports.py +55 -11
- {python_minifier-3.3.0.dist-info → python_minifier-3.4.0.dist-info}/METADATA +5 -4
- {python_minifier-3.3.0.dist-info → python_minifier-3.4.0.dist-info}/RECORD +12 -12
- {python_minifier-3.3.0.dist-info → python_minifier-3.4.0.dist-info}/WHEEL +0 -0
- {python_minifier-3.3.0.dist-info → python_minifier-3.4.0.dist-info}/entry_points.txt +0 -0
- {python_minifier-3.3.0.dist-info → python_minifier-3.4.0.dist-info}/licenses/LICENSE +0 -0
- {python_minifier-3.3.0.dist-info → python_minifier-3.4.0.dist-info}/top_level.txt +0 -0
- {python_minifier-3.3.0.dist-info → python_minifier-3.4.0.dist-info}/zip-safe +0 -0
|
@@ -524,9 +524,15 @@ class ExpressionPrinter(object):
|
|
|
524
524
|
|
|
525
525
|
def visit_DictComp(self, node):
|
|
526
526
|
self.printer.delimiter('{')
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
527
|
+
|
|
528
|
+
if node.value is None:
|
|
529
|
+
self.printer.operator('**')
|
|
530
|
+
self._expression(node.key)
|
|
531
|
+
else:
|
|
532
|
+
self._expression(node.key)
|
|
533
|
+
self.printer.delimiter(':')
|
|
534
|
+
self._expression(node.value)
|
|
535
|
+
|
|
530
536
|
[self.visit_comprehension(x) for x in node.generators]
|
|
531
537
|
self.printer.delimiter('}')
|
|
532
538
|
|
|
@@ -234,6 +234,8 @@ class ModulePrinter(ExpressionPrinter):
|
|
|
234
234
|
def visit_Import(self, node):
|
|
235
235
|
assert isinstance(node, ast.Import)
|
|
236
236
|
|
|
237
|
+
if getattr(node, 'is_lazy', 0) == 1:
|
|
238
|
+
self.printer.keyword('lazy')
|
|
237
239
|
self.printer.keyword('import')
|
|
238
240
|
|
|
239
241
|
delimiter = Delimiter(self.printer)
|
|
@@ -246,6 +248,9 @@ class ModulePrinter(ExpressionPrinter):
|
|
|
246
248
|
def visit_ImportFrom(self, node):
|
|
247
249
|
assert isinstance(node, ast.ImportFrom)
|
|
248
250
|
|
|
251
|
+
if getattr(node, 'is_lazy', 0) == 1:
|
|
252
|
+
self.printer.keyword('lazy')
|
|
253
|
+
|
|
249
254
|
self.printer.keyword('from')
|
|
250
255
|
for _i in range(node.level):
|
|
251
256
|
self.printer.delimiter('.')
|
python_minifier/rename/mapper.py
CHANGED
|
@@ -104,7 +104,9 @@ def add_parent_to_comprehension(node, namespace):
|
|
|
104
104
|
add_parent(node.elt, namespace=node)
|
|
105
105
|
elif hasattr(node, 'key'):
|
|
106
106
|
add_parent(node.key, namespace=node)
|
|
107
|
-
|
|
107
|
+
|
|
108
|
+
if node.value is not None:
|
|
109
|
+
add_parent(node.value, namespace=node)
|
|
108
110
|
|
|
109
111
|
iter_namespace = namespace
|
|
110
112
|
for generator in node.generators:
|
python_minifier/token_printer.py
CHANGED
|
@@ -130,7 +130,7 @@ class TokenPrinter(object):
|
|
|
130
130
|
'or', 'pass', 'raise', 'return',
|
|
131
131
|
'try', 'while', 'with', 'yield', '_',
|
|
132
132
|
'case', 'match', 'print', 'exec',
|
|
133
|
-
'type'
|
|
133
|
+
'type', 'lazy'
|
|
134
134
|
]
|
|
135
135
|
|
|
136
136
|
if self.previous_token in [TokenTypes.Identifier, TokenTypes.Keyword, TokenTypes.SoftKeyword, TokenTypes.NumberLiteral]:
|
|
@@ -138,7 +138,7 @@ class TokenPrinter(object):
|
|
|
138
138
|
|
|
139
139
|
self._code += kw
|
|
140
140
|
|
|
141
|
-
if kw in ['_', 'case', 'match', 'type']:
|
|
141
|
+
if kw in ['_', 'case', 'match', 'type', 'lazy']:
|
|
142
142
|
self.previous_token = TokenTypes.SoftKeyword
|
|
143
143
|
else:
|
|
144
144
|
self.previous_token = TokenTypes.Keyword
|
|
@@ -3,6 +3,13 @@ import python_minifier.ast_compat as ast
|
|
|
3
3
|
from python_minifier.transforms.suite_transformer import SuiteTransformer
|
|
4
4
|
|
|
5
5
|
|
|
6
|
+
def import_kwargs(import_node):
|
|
7
|
+
lazy = getattr(import_node, 'is_lazy', None)
|
|
8
|
+
if lazy is None:
|
|
9
|
+
return {}
|
|
10
|
+
return {'is_lazy': lazy}
|
|
11
|
+
|
|
12
|
+
|
|
6
13
|
class CombineImports(SuiteTransformer):
|
|
7
14
|
"""
|
|
8
15
|
Combine multiple import statements where possible
|
|
@@ -13,29 +20,49 @@ class CombineImports(SuiteTransformer):
|
|
|
13
20
|
|
|
14
21
|
def _combine_import(self, node_list, parent):
|
|
15
22
|
|
|
23
|
+
prev_import = None
|
|
16
24
|
alias = []
|
|
17
|
-
|
|
25
|
+
|
|
26
|
+
def can_merge_with_previous_group(statement):
|
|
27
|
+
if not isinstance(statement, ast.Import):
|
|
28
|
+
return False
|
|
29
|
+
|
|
30
|
+
if prev_import is None:
|
|
31
|
+
return True
|
|
32
|
+
|
|
33
|
+
if getattr(statement, 'is_lazy', None) != getattr(prev_import, 'is_lazy', None):
|
|
34
|
+
return False
|
|
35
|
+
|
|
36
|
+
return True
|
|
37
|
+
|
|
38
|
+
def can_create_group(statement):
|
|
39
|
+
return isinstance(statement, ast.Import)
|
|
18
40
|
|
|
19
41
|
for statement in node_list:
|
|
20
|
-
|
|
21
|
-
|
|
42
|
+
if can_merge_with_previous_group(statement):
|
|
43
|
+
prev_import = statement
|
|
22
44
|
alias += statement.names
|
|
23
45
|
else:
|
|
24
46
|
if alias:
|
|
25
|
-
yield self.add_child(ast.Import(names=alias), parent=parent, namespace=namespace)
|
|
47
|
+
yield self.add_child(ast.Import(names=alias, **import_kwargs(prev_import)), parent=parent, namespace=prev_import.namespace)
|
|
48
|
+
prev_import = None
|
|
26
49
|
alias = []
|
|
27
50
|
|
|
28
|
-
|
|
51
|
+
if can_create_group(statement):
|
|
52
|
+
prev_import = statement
|
|
53
|
+
alias += statement.names
|
|
54
|
+
else:
|
|
55
|
+
yield statement
|
|
29
56
|
|
|
30
57
|
if alias:
|
|
31
|
-
yield self.add_child(ast.Import(names=alias), parent=parent, namespace=namespace)
|
|
58
|
+
yield self.add_child(ast.Import(names=alias, **import_kwargs(prev_import)), parent=parent, namespace=prev_import.namespace)
|
|
32
59
|
|
|
33
60
|
def _combine_import_from(self, node_list, parent):
|
|
34
61
|
|
|
35
62
|
prev_import = None
|
|
36
63
|
alias = []
|
|
37
64
|
|
|
38
|
-
def
|
|
65
|
+
def can_merge_with_previous_group(statement):
|
|
39
66
|
if not isinstance(statement, ast.ImportFrom):
|
|
40
67
|
return False
|
|
41
68
|
|
|
@@ -45,27 +72,44 @@ class CombineImports(SuiteTransformer):
|
|
|
45
72
|
if prev_import is None:
|
|
46
73
|
return True
|
|
47
74
|
|
|
75
|
+
if getattr(statement, 'is_lazy', None) != getattr(prev_import, 'is_lazy', None):
|
|
76
|
+
return False
|
|
77
|
+
|
|
48
78
|
if statement.module == prev_import.module and statement.level == prev_import.level:
|
|
49
79
|
return True
|
|
50
80
|
|
|
51
81
|
return False
|
|
52
82
|
|
|
83
|
+
def can_create_group(statement):
|
|
84
|
+
if not isinstance(statement, ast.ImportFrom):
|
|
85
|
+
return False
|
|
86
|
+
|
|
87
|
+
if len(statement.names) == 1 and statement.names[0].name == '*':
|
|
88
|
+
return False
|
|
89
|
+
|
|
90
|
+
return True
|
|
91
|
+
|
|
53
92
|
for statement in node_list:
|
|
54
|
-
if
|
|
93
|
+
if can_merge_with_previous_group(statement):
|
|
55
94
|
prev_import = statement
|
|
56
95
|
alias += statement.names
|
|
57
96
|
else:
|
|
58
97
|
if alias:
|
|
59
98
|
yield self.add_child(
|
|
60
|
-
ast.ImportFrom(module=prev_import.module, names=alias, level=prev_import.level), parent=parent, namespace=prev_import.namespace
|
|
99
|
+
ast.ImportFrom(module=prev_import.module, names=alias, level=prev_import.level, **import_kwargs(prev_import)), parent=parent, namespace=prev_import.namespace
|
|
61
100
|
)
|
|
101
|
+
prev_import = None
|
|
62
102
|
alias = []
|
|
63
103
|
|
|
64
|
-
|
|
104
|
+
if can_create_group(statement):
|
|
105
|
+
prev_import = statement
|
|
106
|
+
alias += statement.names
|
|
107
|
+
else:
|
|
108
|
+
yield statement
|
|
65
109
|
|
|
66
110
|
if alias:
|
|
67
111
|
yield self.add_child(
|
|
68
|
-
ast.ImportFrom(module=prev_import.module, names=alias, level=prev_import.level), parent=parent, namespace=prev_import.namespace
|
|
112
|
+
ast.ImportFrom(module=prev_import.module, names=alias, level=prev_import.level, **import_kwargs(prev_import)), parent=parent, namespace=prev_import.namespace
|
|
69
113
|
)
|
|
70
114
|
|
|
71
115
|
def suite(self, node_list, parent):
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: python_minifier
|
|
3
|
-
Version: 3.
|
|
3
|
+
Version: 3.4.0
|
|
4
4
|
Summary: Transform Python source code into it's most compact representation
|
|
5
5
|
Home-page: https://github.com/dflook/python-minifier
|
|
6
6
|
Author: Daniel Flook
|
|
@@ -26,13 +26,14 @@ Classifier: Programming Language :: Python :: 3.11
|
|
|
26
26
|
Classifier: Programming Language :: Python :: 3.12
|
|
27
27
|
Classifier: Programming Language :: Python :: 3.13
|
|
28
28
|
Classifier: Programming Language :: Python :: 3.14
|
|
29
|
+
Classifier: Programming Language :: Python :: 3.15
|
|
29
30
|
Classifier: Programming Language :: Python :: 2
|
|
30
31
|
Classifier: Programming Language :: Python :: 2.7
|
|
31
32
|
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
32
33
|
Classifier: Programming Language :: Python :: Implementation :: PyPy
|
|
33
34
|
Classifier: Intended Audience :: Developers
|
|
34
35
|
Classifier: Topic :: Software Development
|
|
35
|
-
Requires-Python: >=2.7, !=3.0.*, !=3.1.*, !=3.2.*, <3.
|
|
36
|
+
Requires-Python: >=2.7, !=3.0.*, !=3.1.*, !=3.2.*, <3.16
|
|
36
37
|
Description-Content-Type: text/markdown
|
|
37
38
|
License-File: LICENSE
|
|
38
39
|
Dynamic: author
|
|
@@ -54,7 +55,7 @@ Transforms Python source code into its most compact representation.
|
|
|
54
55
|
|
|
55
56
|
[Try it out!](https://python-minifier.com)
|
|
56
57
|
|
|
57
|
-
python-minifier currently supports Python 2.7 and Python 3.3 to 3.
|
|
58
|
+
python-minifier currently supports Python 2.7 and Python 3.3 to 3.15. Previous releases supported Python 2.6.
|
|
58
59
|
|
|
59
60
|
* [PyPI](https://pypi.org/project/python-minifier/)
|
|
60
61
|
* [Documentation](https://dflook.github.io/python-minifier/)
|
|
@@ -160,7 +161,7 @@ and outputs source code compatible with the version of the interpreter it is run
|
|
|
160
161
|
This means that if you minify code written for Python 3.11 using python-minifier running with Python 3.12,
|
|
161
162
|
the minified code may only run with Python 3.12.
|
|
162
163
|
|
|
163
|
-
python-minifier runs with and can minify code written for Python 2.7 and Python 3.3 to 3.
|
|
164
|
+
python-minifier runs with and can minify code written for Python 2.7 and Python 3.3 to 3.15.
|
|
164
165
|
|
|
165
166
|
## Usage
|
|
166
167
|
|
|
@@ -4,26 +4,26 @@ python_minifier/__main__.py,sha256=kALlFc8qTJeYXvYEm10N6eBirMbizdYa_9pMD0xVMuU,1
|
|
|
4
4
|
python_minifier/ast_compare.py,sha256=KQyS9TGA1SoCs8uu4iks1IINFb_pEj7x38Q4oiERWnI,3381
|
|
5
5
|
python_minifier/ast_compat.py,sha256=DFJ7WmrEfYXfaby8EWt1aRlcqVPPoXD4Fh9Hnb9dLCU,2250
|
|
6
6
|
python_minifier/ast_printer.py,sha256=TlkyKl9_9ScWeop3W1TwXZ46MJWINfkJ7NvmULpwt4A,3254
|
|
7
|
-
python_minifier/expression_printer.py,sha256=
|
|
7
|
+
python_minifier/expression_printer.py,sha256=yvE9yp7aejolL5UfEIf9YluBu74XiGdAJWeKaiXpIFE,22851
|
|
8
8
|
python_minifier/f_string.py,sha256=eXYXaxEMSB3iHY_M_RXYpeloJV-7TYnhWIGge0KYCk8,18314
|
|
9
9
|
python_minifier/ministring.py,sha256=R0xaAZqMlLu1Jm0aBVSI0n8KZiZV7PTs4RE4UbCmTy8,4359
|
|
10
|
-
python_minifier/module_printer.py,sha256=
|
|
10
|
+
python_minifier/module_printer.py,sha256=ylab7kD2ovuAdh3V5XeQPytm7i2P8goC5I1CGBoxVpk,25844
|
|
11
11
|
python_minifier/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
12
12
|
python_minifier/t_string.py,sha256=z3KzWaSDqvy701SY3dm8VSkiJuiUfopSWGNIm-nDpAo,13261
|
|
13
|
-
python_minifier/token_printer.py,sha256=
|
|
13
|
+
python_minifier/token_printer.py,sha256=lvnqUmAcUGpEAONLYledk_9ZZkW6-ALuacUqnG9qbgo,10032
|
|
14
14
|
python_minifier/util.py,sha256=60iT3XkKlPlZhXQ1NuLB27Wv3ihl-gBC_WjOjEiFn-Q,1184
|
|
15
15
|
python_minifier/ast_annotation/__init__.py,sha256=BJ4gyS-_bytIZf0SP8JJG6FECWf8MUaUi3vOAfD60qQ,2259
|
|
16
16
|
python_minifier/rename/__init__.py,sha256=8DLEFgliakf_5T_m-l1Nd35QxKpM4h7RJyFVpjsxjWA,375
|
|
17
17
|
python_minifier/rename/bind_names.py,sha256=CCL2ZT2px___1yE5euO_Wv423DLQFIp5-D7m5RDV7d8,6918
|
|
18
18
|
python_minifier/rename/binding.py,sha256=WPospKLbZN7nnzDayJ55HMxuS-E5zvOE78RJkKiyPrE,15335
|
|
19
|
-
python_minifier/rename/mapper.py,sha256=
|
|
19
|
+
python_minifier/rename/mapper.py,sha256=u36_GRGzATSjv5E86sF-Jvefrns_QXzsUuJ5GLPiTTs,6522
|
|
20
20
|
python_minifier/rename/name_generator.py,sha256=70Klx2DteYRpBT8dr6jYDB31ARfinS42e08kKlWAzLg,1269
|
|
21
21
|
python_minifier/rename/rename_literals.py,sha256=2OM8mW_2j0kXFNZfFQyW9DacIcB6_VYkjv3nmpjRtN8,7536
|
|
22
22
|
python_minifier/rename/renamer.py,sha256=UQWrWrmntT0laNjTxEcH-cK4nZXAzi6LtJCI_STYZbo,6601
|
|
23
23
|
python_minifier/rename/resolve_names.py,sha256=VbePyUUqggvvcF3fAC6XMv6b3Kmb_cmlO9G7vf5Ti-c,4320
|
|
24
24
|
python_minifier/rename/util.py,sha256=ItJykxM_QRjIePMcKYo-LngmP5hLQZK-bOZIefg1cKA,5469
|
|
25
25
|
python_minifier/transforms/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
26
|
-
python_minifier/transforms/combine_imports.py,sha256=
|
|
26
|
+
python_minifier/transforms/combine_imports.py,sha256=4uuiFDd1EvYdpAE1wp37n5relFknju-ielG89T9-eKM,3875
|
|
27
27
|
python_minifier/transforms/constant_folding.py,sha256=08YEiSgLeiAKP73Q9p6sS4VDkn_S0zYHtebcgUBWJ6s,6939
|
|
28
28
|
python_minifier/transforms/remove_annotations.py,sha256=qUCdl42yvq1g7B43d88EOz6Jf51A5zogYBlFHGnyugU,4938
|
|
29
29
|
python_minifier/transforms/remove_annotations_options.py,sha256=kzg-gEPwhrCZxsuzdpEWjqnhsyF89hnIPv1t-IRty64,1889
|
|
@@ -38,10 +38,10 @@ python_minifier/transforms/remove_object_base.py,sha256=j4se6OXyZK1lr_ABmGT0Oivu
|
|
|
38
38
|
python_minifier/transforms/remove_pass.py,sha256=S9e59nBEZ8rBBifvAhbPRDTfUA7s8_a7pSIsZbFZD2A,735
|
|
39
39
|
python_minifier/transforms/remove_posargs.py,sha256=aV0wFnGiDXu4uQBQP7-cB1uLSF3mamIq5-txvDg8BVo,314
|
|
40
40
|
python_minifier/transforms/suite_transformer.py,sha256=y5rx0Mc31KfE3je3sXqMvAhJ4hy-JoDC4nDvPCLw13I,7639
|
|
41
|
-
python_minifier-3.
|
|
42
|
-
python_minifier-3.
|
|
43
|
-
python_minifier-3.
|
|
44
|
-
python_minifier-3.
|
|
45
|
-
python_minifier-3.
|
|
46
|
-
python_minifier-3.
|
|
47
|
-
python_minifier-3.
|
|
41
|
+
python_minifier-3.4.0.dist-info/licenses/LICENSE,sha256=FzsyDHb8pAZupSGFjIOuHcHMlFf6N-aIxq9gOYGbNyE,1069
|
|
42
|
+
python_minifier-3.4.0.dist-info/METADATA,sha256=vcL1qc6-_rx2PoXyySaud4JpEFPIah4vxQA3tx17wpU,6807
|
|
43
|
+
python_minifier-3.4.0.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
|
|
44
|
+
python_minifier-3.4.0.dist-info/entry_points.txt,sha256=ew5TjfSuFJMd5wefRaK3zeoPc_MNQ_o4XN2JiJC5v8Q,59
|
|
45
|
+
python_minifier-3.4.0.dist-info/top_level.txt,sha256=4SRDfWKi_KMq7LDrjlzUFoDCs6INYPtxc1Pun4z8LsU,16
|
|
46
|
+
python_minifier-3.4.0.dist-info/zip-safe,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
|
|
47
|
+
python_minifier-3.4.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|