Skip to content

Python 3.12 #94

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 55 commits into from
Sep 15, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
e564e7c
Build for python 3.12
dflook Sep 19, 2023
5bf58f8
Add tests for python 3.12 new type parameter syntax
dflook Sep 19, 2023
0920e8f
Implement Python 3.12 type parameters
dflook Sep 19, 2023
008cd55
Fix version sourcing on Python 3.12
dflook Sep 19, 2023
6628f9a
Avoid using setuptools
dflook Sep 19, 2023
29147c2
Add empty manifest for 3.12
dflook Sep 20, 2023
e4a793e
Introduce backward compatible ast module
dflook Sep 23, 2023
e82874f
3.12-rc3
dflook Sep 25, 2023
1329e9d
Set namespace for TypeParam nodes
dflook Sep 26, 2023
4831e3b
Avoid using setuptools in corpus test
dflook Sep 26, 2023
85da9f8
Fix type warnings
dflook Sep 26, 2023
d3428a4
Skip testing incompatible python/ref
dflook Sep 26, 2023
2b85ff1
Fix stubtest
dflook Sep 27, 2023
b9a961d
Fix report generation with missing results
dflook Sep 27, 2023
ef4cf30
Fix corpus test
dflook Sep 27, 2023
420f84c
Update report for 3.12
dflook Sep 28, 2023
8800954
Fix report generation for empty result sets
dflook Sep 28, 2023
6731de2
Create wheel
dflook Sep 29, 2023
bd002c7
Retest with test-set-1
dflook Sep 30, 2023
c168261
Fix python2 package
dflook Sep 30, 2023
981e99e
Fix python2 wheel build
dflook Sep 30, 2023
f34ebbd
Add hypothesis tests for type parameters
dflook Sep 30, 2023
654a3e1
Rollback to actions/checkout@v3
dflook Jan 8, 2024
0a7cd60
Allow reusing quotes in f-strings
dflook Jan 9, 2024
710f128
Relax restrictions about backslashes in pep701 f-strings
dflook Jan 11, 2024
baee4a8
Wrap lambda expressions in parentheses
dflook Jan 11, 2024
0da44dc
Update python 12 build container to use Python 3.12.1
dflook Jan 12, 2024
34e4ede
Initial python 3.12 test manifest
dflook Jan 12, 2024
8492be8
Allow backslashes in pep701 f-strings
dflook Jan 13, 2024
6e00ae0
Don't hoist literals in __slots__
dflook Aug 6, 2024
3ed7c91
Add python3.12 xtest manifest
dflook Aug 6, 2024
a765c26
Fix test_no_hoist_slots
dflook Aug 6, 2024
326b0f3
f
dflook Aug 6, 2024
3343406
Fix no hoist __slots__ test on Python 2
dflook Aug 6, 2024
0552d38
Remove tests that don't work on actions runners
dflook Aug 6, 2024
4174192
Update to checkout v4
dflook Aug 6, 2024
3a008a0
Try and stop github from breaking my jobs
dflook Aug 6, 2024
9c2a03e
Remove test that can't pass in CI
dflook Aug 7, 2024
c2496f1
Fix test_no_hoist_slots
dflook Aug 7, 2024
bb9255e
Remove another test that doesn't work in CI
dflook Aug 7, 2024
8af0d1f
knock out another one that doesn't work in CI
dflook Aug 7, 2024
f236db3
Remove tests that rely on the behaviour of external systems
dflook Aug 8, 2024
194b5fc
Place Names bindings in load context within a ClassDef in non-local n…
dflook Aug 9, 2024
1bec27f
Disallow renaming for non-local names used in class scope in store co…
dflook Aug 9, 2024
717d0e0
Add namespace tests
dflook Aug 17, 2024
c8c847e
Make sure combined imports maintain the same namespace
dflook Aug 30, 2024
54d2436
Add a cleanup step for xtests
dflook Aug 30, 2024
0b71b70
Log assertion errors from corpus
dflook Aug 30, 2024
b6ec290
Disallow renaming of names used in store context in class namespace
dflook Aug 31, 2024
61ee2d7
Only remove brackets from raises for builtin exceptions
dflook Aug 31, 2024
333acfe
Merge pull request #101 from dflook/python312-class-names
dflook Aug 31, 2024
d5cc78d
Enable renaming of type parameters
dflook Sep 1, 2024
e128644
Disable renaming of type parameters
dflook Sep 5, 2024
03ec99a
Fix errors in manifests
dflook Sep 5, 2024
678a761
Merge pull request #104 from dflook/python312-typeparam-rename
dflook Sep 6, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Disallow renaming of names used in store context in class namespace
These will become class attributes.
This fixes situations where renaming was allowed due to the actual namebinding being placed in a nonlocal scope by a name in load context in the class scope.
  • Loading branch information
dflook committed Aug 31, 2024
commit b6ec2902986e548130b765ece69670a29b720f92
30 changes: 22 additions & 8 deletions src/python_minifier/rename/resolve_names.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ def get_binding(name, namespace):
namespace.bindings.append(binding)
return binding

def get_binding_disallow_class_namespace_rename(name, namespace):
binding = get_binding(name, namespace)

if isinstance(namespace, ast.ClassDef):
# This name will become an attribute of a class, so it can't be renamed
binding.disallow_rename()

return binding

def resolve_names(node):
"""
Expand All @@ -54,36 +62,42 @@ def resolve_names(node):
binding.disallow_rename()

elif isinstance(node, ast.ClassDef) and node.name in node.namespace.nonlocal_names:
get_binding(node.name, node.namespace).add_reference(node)
binding = get_binding_disallow_class_namespace_rename(node.name, node.namespace)
binding.add_reference(node)

elif is_ast_node(node, (ast.FunctionDef, 'AsyncFunctionDef')) and node.name in node.namespace.nonlocal_names:
get_binding(node.name, node.namespace).add_reference(node)
binding = get_binding_disallow_class_namespace_rename(node.name, node.namespace)
binding.add_reference(node)

elif isinstance(node, ast.alias):

if node.asname is not None:
if node.asname in node.namespace.nonlocal_names:
get_binding(node.asname, node.namespace).add_reference(node)
binding = get_binding_disallow_class_namespace_rename(node.asname, node.namespace)
binding.add_reference(node)

else:
# This binds the root module only for a dotted import
root_module = node.name.split('.')[0]

if root_module in node.namespace.nonlocal_names:
binding = get_binding(root_module, node.namespace)
binding = get_binding_disallow_class_namespace_rename(root_module, node.namespace)
binding.add_reference(node)

if '.' in node.name:
binding.disallow_rename()

elif isinstance(node, ast.ExceptHandler) and node.name is not None:
if isinstance(node.name, str) and node.name in node.namespace.nonlocal_names:
get_binding(node.name, node.namespace).add_reference(node)
get_binding_disallow_class_namespace_rename(node.name, node.namespace).add_reference(node)

elif is_ast_node(node, 'Nonlocal'):
for name in node.names:
get_binding(name, node.namespace).add_reference(node)
get_binding_disallow_class_namespace_rename(name, node.namespace).add_reference(node)
elif is_ast_node(node, ('MatchAs', 'MatchStar')) and node.name in node.namespace.nonlocal_names:
get_binding(node.name, node.namespace).add_reference(node)
get_binding_disallow_class_namespace_rename(node.name, node.namespace).add_reference(node)
elif is_ast_node(node, 'MatchMapping') and node.rest in node.namespace.nonlocal_names:
get_binding(node.rest, node.namespace).add_reference(node)
get_binding_disallow_class_namespace_rename(node.rest, node.namespace).add_reference(node)

elif is_ast_node(node, 'Exec'):
get_global_namespace(node).tainted = True
Expand Down
Loading
Loading