Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
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
516 changes: 258 additions & 258 deletions Lib/_opcode_metadata.py

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions Lib/_pydatetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,13 @@ def _build_struct_time(y, m, d, hh, mm, ss, dstflag):
return _time.struct_time((y, m, d, hh, mm, ss, wday, dnum, dstflag))

def _format_time(hh, mm, ss, us, timespec='auto'):
specs = {
'hours': '{:02d}',
'minutes': '{:02d}:{:02d}',
'seconds': '{:02d}:{:02d}:{:02d}',
'milliseconds': '{:02d}:{:02d}:{:02d}.{:03d}',
'microseconds': '{:02d}:{:02d}:{:02d}.{:06d}'
}
specs = frozendict(
hours= '{:02d}',
minutes= '{:02d}:{:02d}',
seconds= '{:02d}:{:02d}:{:02d}',
milliseconds= '{:02d}:{:02d}:{:02d}.{:03d}',
microseconds= '{:02d}:{:02d}:{:02d}.{:06d}'
)

if timespec == 'auto':
# Skip trailing microseconds when us==0.
Expand Down
4 changes: 2 additions & 2 deletions Lib/bdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class BdbQuit(Exception):
E = sys.monitoring.events

class _MonitoringTracer:
EVENT_CALLBACK_MAP = {
EVENT_CALLBACK_MAP = frozendict({
E.PY_START: 'call',
E.PY_RESUME: 'call',
E.PY_THROW: 'call',
Expand All @@ -32,7 +32,7 @@ class _MonitoringTracer:
E.RAISE: 'exception',
E.STOP_ITERATION: 'exception',
E.INSTRUCTION: 'opcode',
}
})

GLOBAL_EVENTS = E.PY_START | E.PY_RESUME | E.PY_THROW | E.PY_UNWIND | E.RAISE
LOCAL_EVENTS = E.LINE | E.JUMP | E.PY_RETURN | E.PY_YIELD | E.STOP_ITERATION
Expand Down
8 changes: 4 additions & 4 deletions Lib/json/decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,19 @@ def __reduce__(self):
return self.__class__, (self.msg, self.doc, self.pos)


_CONSTANTS = {
_CONSTANTS = frozendict({
'-Infinity': NegInf,
'Infinity': PosInf,
'NaN': NaN,
}
})


HEXDIGITS = re.compile(r'[0-9A-Fa-f]{4}', FLAGS)
STRINGCHUNK = re.compile(r'(.*?)(["\\\x00-\x1f])', FLAGS)
BACKSLASH = {
BACKSLASH = frozendict({
'"': '"', '\\': '\\', '/': '/',
'b': '\b', 'f': '\f', 'n': '\n', 'r': '\r', 't': '\t',
}
})

def _decode_uXXXX(s, pos, _m=HEXDIGITS.match):
esc = _m(s, pos + 1)
Expand Down
3 changes: 3 additions & 0 deletions Lib/json/encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
for i in range(0x20):
ESCAPE_DCT.setdefault(chr(i), '\\u{0:04x}'.format(i))
#ESCAPE_DCT.setdefault(chr(i), '\\u%04x' % (i,))

# freeze the dict to prevent accidental modifications
ESCAPE_DCT = frozendict(ESCAPE_DCT)
del i

INFINITY = float('inf')
Expand Down
8 changes: 1 addition & 7 deletions Lib/json/tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,7 @@
(?P<null>null)
''', re.VERBOSE)

_group_to_theme_color = {
"key": "definition",
"string": "string",
"number": "number",
"boolean": "keyword",
"null": "keyword",
}
_group_to_theme_color = frozendict(key="definition",string="string",number="number",boolean="keyword",null="keyword")


def _colorize_json(json_str, theme):
Expand Down
46 changes: 23 additions & 23 deletions Lib/opcode.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,78 +45,78 @@

hascompare = [opmap["COMPARE_OP"]]

_cache_format = {
"LOAD_GLOBAL": {
_cache_format = frozendict(
LOAD_GLOBAL= {
"counter": 1,
"index": 1,
"module_keys_version": 1,
"builtin_keys_version": 1,
},
"BINARY_OP": {
BINARY_OP= {
"counter": 1,
"descr": 4,
},
"UNPACK_SEQUENCE": {
UNPACK_SEQUENCE= {
"counter": 1,
},
"COMPARE_OP": {
COMPARE_OP= {
"counter": 1,
},
"CONTAINS_OP": {
CONTAINS_OP= {
"counter": 1,
},
"FOR_ITER": {
FOR_ITER= {
"counter": 1,
},
"LOAD_SUPER_ATTR": {
LOAD_SUPER_ATTR= {
"counter": 1,
},
"LOAD_ATTR": {
LOAD_ATTR= {
"counter": 1,
"version": 2,
"keys_version": 2,
"descr": 4,
},
"STORE_ATTR": {
STORE_ATTR= {
"counter": 1,
"version": 2,
"index": 1,
},
"CALL": {
CALL= {
"counter": 1,
"func_version": 2,
},
"CALL_KW": {
CALL_KW= {
"counter": 1,
"func_version": 2,
},
"STORE_SUBSCR": {
STORE_SUBSCR= {
"counter": 1,
},
"SEND": {
SEND= {
"counter": 1,
},
"JUMP_BACKWARD": {
JUMP_BACKWARD= {
"counter": 1,
},
"TO_BOOL": {
TO_BOOL= {
"counter": 1,
"version": 2,
},
"POP_JUMP_IF_TRUE": {
POP_JUMP_IF_TRUE= {
"counter": 1,
},
"POP_JUMP_IF_FALSE": {
POP_JUMP_IF_FALSE= {
"counter": 1,
},
"POP_JUMP_IF_NONE": {
POP_JUMP_IF_NONE= {
"counter": 1,
},
"POP_JUMP_IF_NOT_NONE": {
POP_JUMP_IF_NOT_NONE= {
"counter": 1,
},
}
)

_inline_cache_entries = {
_inline_cache_entries = frozendict({
name : sum(value.values()) for (name, value) in _cache_format.items()
}
})
4 changes: 2 additions & 2 deletions Objects/dictobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -5368,7 +5368,7 @@ dictiter_iternextvalue_lock_held(PyDictObject *d, PyObject *self)
PyObject *value;
Py_ssize_t i;

assert (PyDict_Check(d));
// assert (PyDict_Check(d));
ASSERT_DICT_LOCKED(d);

if (di->di_used != d->ma_used) {
Expand Down Expand Up @@ -5490,7 +5490,7 @@ dictiter_iternextitem_lock_held(PyDictObject *d, PyObject *self,
PyObject *key, *value;
Py_ssize_t i;

assert (_PyAnyDict_Check(d));
// assert (_PyAnyDict_Check(d));
ASSERT_DICT_LOCKED(d);

if (di->di_used != d->ma_used) {
Expand Down
18 changes: 9 additions & 9 deletions Tools/cases_generator/py_metadata_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,35 +30,35 @@ def get_specialized(analysis: Analysis) -> set[str]:


def generate_specializations(analysis: Analysis, out: CWriter) -> None:
out.emit("_specializations = {\n")
out.emit("_specializations = frozendict(\n")
for family in analysis.families.values():
out.emit(f'"{family.name}": [\n')
out.emit(f'{family.name}= [\n')
for member in family.members:
out.emit(f' "{member.name}",\n')
out.emit("],\n")
out.emit("}\n\n")
out.emit(")\n\n")


def generate_specialized_opmap(analysis: Analysis, out: CWriter) -> None:
out.emit("_specialized_opmap = {\n")
out.emit("_specialized_opmap = frozendict(\n")
names = []
for family in analysis.families.values():
for member in family.members:
if member.name == family.name:
continue
names.append(member.name)
for name in sorted(names):
out.emit(f"'{name}': {analysis.opmap[name]},\n")
out.emit("}\n\n")
out.emit(f"{name}= {analysis.opmap[name]},\n")
out.emit(")\n\n")


def generate_opmap(analysis: Analysis, out: CWriter) -> None:
specialized = get_specialized(analysis)
out.emit("opmap = {\n")
out.emit("opmap = frozendict(\n")
for inst, op in analysis.opmap.items():
if inst not in specialized:
out.emit(f"'{inst}': {analysis.opmap[inst]},\n")
out.emit("}\n\n")
out.emit(f"{inst}= {analysis.opmap[inst]},\n")
out.emit(")\n\n")


def generate_py_metadata(
Expand Down