masking nits

This commit is contained in:
Josh Wiedemeier
2025-12-10 10:10:04 -06:00
parent f208b407fe
commit 070b5a356c
4 changed files with 10 additions and 3 deletions
+5 -1
View File
@@ -1,4 +1,5 @@
import ast
import sys
import re
import copy
from pylingual.masking.global_masker import Masker
@@ -28,7 +29,10 @@ class customUnparser(ast._Unparser):
def visit_FormattedValue(self, node):
def unparse_inner(inner):
unparser = type(self)(self.masker, _avoid_backslashes=True)
if PythonVersion(sys.version_info) <= (3, 11):
unparser = type(self)(self.masker, _avoid_backslashes=True)
else:
unparser = type(self)(self.masker)
unparser.set_precedence(ast._Precedence.TEST.next(), inner)
return unparser.visit(inner)
+1 -1
View File
@@ -69,7 +69,7 @@ class Masker:
def mask(self, tok):
"""Mask a token, must be in the global_table."""
return self.global_tab[tok] if not any(tok == t and type(tok) == type(t) for t in self.blacklist) else tok
return self.global_tab[tok] if not any(tok == t and type(tok) is type(t) for t in self.blacklist) else tok
def unmask(self, value):
"""Unmask a token, value must be a metatoken value in the global_table; or this function will fail loudly"""
+1 -1
View File
@@ -43,7 +43,7 @@ def create_global_masker(bytecode: EditableBytecode) -> Masker:
# add LOAD_SMALL_INT values to consts (3.14+)
if bc.version >= (3, 14):
for inst in bc.instructions:
if inst.opname == "LOAD_SMALL_INT" and inst.argval not in consts:
if inst.opname == "LOAD_SMALL_INT": # duplicate consts will be filtered out later
consts.append(inst.argval)
while consts:
+3
View File
@@ -100,3 +100,6 @@ docstring-code-line-length = "dynamic"
members = [
"pylingual/tools",
]
[tool.uv.sources]
xdis = { git = "https://github.com/jdw170000/python-xdis", rev = "python-3.14" }