-
Notifications
You must be signed in to change notification settings - Fork 19
Python 3.14 text signatures, sizeof, and SyntaxError offsets #1149
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
Changes from 42 commits
2ede91a
1891103
0b64e3d
2e77eea
85ecc3e
8334c03
cca0ff3
52a9780
a3925af
a072724
9e96261
0f6a04e
7a5da10
7bb68e7
689cee8
45aed77
6c43ce7
dfbe076
24cf766
1bb38df
7d2af75
a183e01
7dee244
6f69d9f
e7d5754
dd23fda
9d82733
42f1b9c
26f93b5
d94a0d6
870b5dc
34b7868
5d655d9
814d3ac
fe4b496
81b3146
92feee0
ec79672
0c0afed
548eda3
ea731d7
ae7d5b2
6cbd410
4959bb5
8bd88f9
0ef4a58
e57797e
ccdf0cc
238629c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| """CPython 3.14 text signatures for bool's own descriptors.""" | ||
|
|
||
| import inspect | ||
|
|
||
|
|
||
| EXPECTED = { | ||
| "__new__": "($type, *args, **kwargs)", | ||
| "__repr__": "($self, /)", | ||
| "__invert__": "($self, /)", | ||
| "__and__": "($self, value, /)", | ||
| "__rand__": "($self, value, /)", | ||
| "__or__": "($self, value, /)", | ||
| "__ror__": "($self, value, /)", | ||
| "__xor__": "($self, value, /)", | ||
| "__rxor__": "($self, value, /)", | ||
| } | ||
|
|
||
| for name, signature in EXPECTED.items(): | ||
| descriptor = bool.__dict__[name] | ||
| assert descriptor.__text_signature__ == signature, name | ||
|
|
||
| assert str(inspect.signature(bool.__repr__)) == "(self, /)" | ||
| assert str(inspect.signature(bool.__and__)) == "(self, value, /)" | ||
|
|
||
| print("OK") |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| """CPython 3.14 text signatures for functions in the builtins module.""" | ||
|
|
||
| import builtins | ||
| import inspect | ||
|
|
||
|
|
||
| EXPECTED = { | ||
| "__import__": "($module, /, name, globals=None, locals=None, fromlist=(),\n level=0)", | ||
| "abs": "($module, x, /)", | ||
| "aiter": "($module, async_iterable, /)", | ||
| "all": "($module, iterable, /)", | ||
| "anext": "($module, aiterator, default=<unrepresentable>, /)", | ||
| "any": "($module, iterable, /)", | ||
| "ascii": "($module, obj, /)", | ||
| "bin": "($module, number, /)", | ||
| "breakpoint": "($module, /, *args, **kws)", | ||
| "callable": "($module, obj, /)", | ||
| "chr": "($module, i, /)", | ||
| "compile": "($module, /, source, filename, mode, flags=0,\n dont_inherit=False, optimize=-1, *, _feature_version=-1)", | ||
| "delattr": "($module, obj, name, /)", | ||
| "divmod": "($module, x, y, /)", | ||
| "eval": "($module, source, /, globals=None, locals=None)", | ||
| "exec": "($module, source, /, globals=None, locals=None, *, closure=None)", | ||
| "format": "($module, value, format_spec='', /)", | ||
| "globals": "($module, /)", | ||
| "hasattr": "($module, obj, name, /)", | ||
| "hash": "($module, obj, /)", | ||
| "hex": "($module, number, /)", | ||
| "id": "($module, obj, /)", | ||
| "input": "($module, prompt='', /)", | ||
| "isinstance": "($module, obj, class_or_tuple, /)", | ||
| "issubclass": "($module, cls, class_or_tuple, /)", | ||
| "len": "($module, obj, /)", | ||
| "locals": "($module, /)", | ||
| "oct": "($module, number, /)", | ||
| "open": "($module, /, file, mode='r', buffering=-1, encoding=None,\n errors=None, newline=None, closefd=True, opener=None)", | ||
| "ord": "($module, character, /)", | ||
| "pow": "($module, /, base, exp, mod=None)", | ||
| "print": "($module, /, *args, sep=' ', end='\\n', file=None, flush=False)", | ||
| "repr": "($module, obj, /)", | ||
| "round": "($module, /, number, ndigits=None)", | ||
| "setattr": "($module, obj, name, value, /)", | ||
| "sorted": "($module, iterable, /, *, key=None, reverse=False)", | ||
| "sum": "($module, iterable, /, start=0)", | ||
| } | ||
|
|
||
| for name, signature in EXPECTED.items(): | ||
| assert getattr(builtins, name).__text_signature__ == signature, name | ||
|
|
||
| for name in ("__build_class__", "dir", "getattr", "iter", "max", "min", "next", "vars"): | ||
| assert getattr(builtins, name).__text_signature__ is None, name | ||
|
|
||
| assert str(inspect.signature(len)) == "(obj, /)" | ||
| assert str(inspect.signature(sorted)) == ( | ||
| "(iterable, /, *, key=None, reverse=False)" | ||
| ) | ||
| assert str(inspect.signature(open)) == ( | ||
| "(file, mode='r', buffering=-1, encoding=None, errors=None, newline=None, " | ||
| "closefd=True, opener=None)" | ||
| ) | ||
| assert str(inspect.signature(print)) == ( | ||
| "(*args, sep=' ', end='\\n', file=None, flush=False)" | ||
| ) | ||
|
|
||
| print("OK") |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| """CPython 3.14 text signatures for bytearray descriptors.""" | ||
|
|
||
| import inspect | ||
|
|
||
|
|
||
| EXPECTED = { | ||
| "__new__": "($type, *args, **kwargs)", | ||
| "__repr__": "($self, /)", | ||
| "__str__": "($self, /)", | ||
| "__lt__": "($self, value, /)", | ||
| "__le__": "($self, value, /)", | ||
| "__eq__": "($self, value, /)", | ||
| "__ne__": "($self, value, /)", | ||
| "__gt__": "($self, value, /)", | ||
| "__ge__": "($self, value, /)", | ||
| "__iter__": "($self, /)", | ||
| "__init__": "($self, /, *args, **kwargs)", | ||
| "__buffer__": "($self, flags, /)", | ||
| "__release_buffer__": "($self, buffer, /)", | ||
| "__mod__": "($self, value, /)", | ||
| "__rmod__": "($self, value, /)", | ||
| "__len__": "($self, /)", | ||
| "__getitem__": "($self, key, /)", | ||
| "__setitem__": "($self, key, value, /)", | ||
| "__delitem__": "($self, key, /)", | ||
| "__add__": "($self, value, /)", | ||
| "__mul__": "($self, value, /)", | ||
| "__rmul__": "($self, value, /)", | ||
| "__contains__": "($self, key, /)", | ||
| "__iadd__": "($self, value, /)", | ||
| "__imul__": "($self, value, /)", | ||
| "__alloc__": "($self, /)", | ||
| "__reduce__": "($self, /)", | ||
| "__reduce_ex__": "($self, proto=0, /)", | ||
| "__sizeof__": "($self, /)", | ||
| "append": "($self, item, /)", | ||
| "capitalize": "($self, /)", | ||
| "center": "($self, width, fillchar=b' ', /)", | ||
| "clear": "($self, /)", | ||
| "copy": "($self, /)", | ||
| "count": "($self, sub[, start[, end]], /)", | ||
| "decode": "($self, /, encoding='utf-8', errors='strict')", | ||
| "endswith": "($self, suffix[, start[, end]], /)", | ||
| "expandtabs": "($self, /, tabsize=8)", | ||
| "extend": "($self, iterable_of_ints, /)", | ||
| "find": "($self, sub[, start[, end]], /)", | ||
| "hex": "($self, /, sep=<unrepresentable>, bytes_per_sep=1)", | ||
| "index": "($self, sub[, start[, end]], /)", | ||
| "insert": "($self, index, item, /)", | ||
| "isalnum": "($self, /)", | ||
| "isalpha": "($self, /)", | ||
| "isascii": "($self, /)", | ||
| "isdigit": "($self, /)", | ||
| "islower": "($self, /)", | ||
| "isspace": "($self, /)", | ||
| "istitle": "($self, /)", | ||
| "isupper": "($self, /)", | ||
| "join": "($self, iterable_of_bytes, /)", | ||
| "ljust": "($self, width, fillchar=b' ', /)", | ||
| "lower": "($self, /)", | ||
| "lstrip": "($self, bytes=None, /)", | ||
| "partition": "($self, sep, /)", | ||
| "pop": "($self, index=-1, /)", | ||
| "remove": "($self, value, /)", | ||
| "replace": "($self, old, new, count=-1, /)", | ||
| "removeprefix": "($self, prefix, /)", | ||
| "removesuffix": "($self, suffix, /)", | ||
| "resize": "($self, size, /)", | ||
| "reverse": "($self, /)", | ||
| "rfind": "($self, sub[, start[, end]], /)", | ||
| "rindex": "($self, sub[, start[, end]], /)", | ||
| "rjust": "($self, width, fillchar=b' ', /)", | ||
| "rpartition": "($self, sep, /)", | ||
| "rsplit": "($self, /, sep=None, maxsplit=-1)", | ||
| "rstrip": "($self, bytes=None, /)", | ||
| "split": "($self, /, sep=None, maxsplit=-1)", | ||
| "splitlines": "($self, /, keepends=False)", | ||
| "startswith": "($self, prefix[, start[, end]], /)", | ||
| "strip": "($self, bytes=None, /)", | ||
| "swapcase": "($self, /)", | ||
| "title": "($self, /)", | ||
| "translate": "($self, table, /, delete=b'')", | ||
| "upper": "($self, /)", | ||
| "zfill": "($self, width, /)", | ||
| } | ||
|
|
||
| for name, signature in EXPECTED.items(): | ||
| assert bytearray.__dict__[name].__text_signature__ == signature, name | ||
|
|
||
| raw_maketrans = bytearray.__dict__["maketrans"] | ||
| assert not hasattr(raw_maketrans, "__text_signature__") | ||
| assert bytearray.maketrans.__text_signature__ == "(frm, to, /)" | ||
| assert bytearray.__dict__["fromhex"].__text_signature__ == "($type, string, /)" | ||
|
|
||
| assert str(inspect.signature(bytearray.decode)) == ( | ||
| "(self, /, encoding='utf-8', errors='strict')" | ||
| ) | ||
| assert str(inspect.signature(bytearray.resize)) == "(self, size, /)" | ||
| assert str(inspect.signature(bytearray.fromhex)) == "(string, /)" | ||
|
|
||
| print("OK") |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| """CPython 3.14 text signatures for bytes descriptors.""" | ||
|
|
||
| import inspect | ||
|
|
||
|
|
||
| EXPECTED = { | ||
| "__new__": "($type, *args, **kwargs)", | ||
| "__repr__": "($self, /)", | ||
| "__hash__": "($self, /)", | ||
| "__str__": "($self, /)", | ||
| "__lt__": "($self, value, /)", | ||
| "__le__": "($self, value, /)", | ||
| "__eq__": "($self, value, /)", | ||
| "__ne__": "($self, value, /)", | ||
| "__gt__": "($self, value, /)", | ||
| "__ge__": "($self, value, /)", | ||
| "__iter__": "($self, /)", | ||
| "__buffer__": "($self, flags, /)", | ||
| "__mod__": "($self, value, /)", | ||
| "__rmod__": "($self, value, /)", | ||
| "__len__": "($self, /)", | ||
| "__getitem__": "($self, key, /)", | ||
| "__add__": "($self, value, /)", | ||
| "__mul__": "($self, value, /)", | ||
| "__rmul__": "($self, value, /)", | ||
| "__contains__": "($self, key, /)", | ||
| "__getnewargs__": "($self, /)", | ||
| "__bytes__": "($self, /)", | ||
| "capitalize": "($self, /)", | ||
| "center": "($self, width, fillchar=b' ', /)", | ||
| "count": "($self, sub[, start[, end]], /)", | ||
| "decode": "($self, /, encoding='utf-8', errors='strict')", | ||
| "endswith": "($self, suffix[, start[, end]], /)", | ||
| "expandtabs": "($self, /, tabsize=8)", | ||
| "find": "($self, sub[, start[, end]], /)", | ||
| "hex": "($self, /, sep=<unrepresentable>, bytes_per_sep=1)", | ||
| "index": "($self, sub[, start[, end]], /)", | ||
| "isalnum": "($self, /)", | ||
| "isalpha": "($self, /)", | ||
| "isascii": "($self, /)", | ||
| "isdigit": "($self, /)", | ||
| "islower": "($self, /)", | ||
| "isspace": "($self, /)", | ||
| "istitle": "($self, /)", | ||
| "isupper": "($self, /)", | ||
| "join": "($self, iterable_of_bytes, /)", | ||
| "ljust": "($self, width, fillchar=b' ', /)", | ||
| "lower": "($self, /)", | ||
| "lstrip": "($self, bytes=None, /)", | ||
| "partition": "($self, sep, /)", | ||
| "replace": "($self, old, new, count=-1, /)", | ||
| "removeprefix": "($self, prefix, /)", | ||
| "removesuffix": "($self, suffix, /)", | ||
| "rfind": "($self, sub[, start[, end]], /)", | ||
| "rindex": "($self, sub[, start[, end]], /)", | ||
| "rjust": "($self, width, fillchar=b' ', /)", | ||
| "rpartition": "($self, sep, /)", | ||
| "rsplit": "($self, /, sep=None, maxsplit=-1)", | ||
| "rstrip": "($self, bytes=None, /)", | ||
| "split": "($self, /, sep=None, maxsplit=-1)", | ||
| "splitlines": "($self, /, keepends=False)", | ||
| "startswith": "($self, prefix[, start[, end]], /)", | ||
| "strip": "($self, bytes=None, /)", | ||
| "swapcase": "($self, /)", | ||
| "title": "($self, /)", | ||
| "translate": "($self, table, /, delete=b'')", | ||
| "upper": "($self, /)", | ||
| "zfill": "($self, width, /)", | ||
| } | ||
|
|
||
| for name, signature in EXPECTED.items(): | ||
| assert bytes.__dict__[name].__text_signature__ == signature, name | ||
|
|
||
| raw_maketrans = bytes.__dict__["maketrans"] | ||
| assert not hasattr(raw_maketrans, "__text_signature__") | ||
| assert bytes.maketrans.__text_signature__ == "(frm, to, /)" | ||
| assert bytes.__dict__["fromhex"].__text_signature__ == "($type, string, /)" | ||
|
|
||
| assert str(inspect.signature(bytes.decode)) == ( | ||
| "(self, /, encoding='utf-8', errors='strict')" | ||
| ) | ||
| assert str(inspect.signature(bytes.replace)) == "(self, old, new, count=-1, /)" | ||
| assert str(inspect.signature(bytes.fromhex)) == "(string, /)" | ||
|
|
||
| print("OK") |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| """CPython 3.14 text signatures for complex descriptors.""" | ||
|
|
||
| import inspect | ||
|
|
||
|
|
||
| VALUE_BINARY = { | ||
| name: "($self, value, /)" | ||
| for name in ( | ||
| "__lt__", "__le__", "__eq__", "__ne__", "__gt__", "__ge__", | ||
| "__add__", "__radd__", "__sub__", "__rsub__", "__mul__", "__rmul__", | ||
| "__truediv__", "__rtruediv__", | ||
| ) | ||
| } | ||
| SELF_ONLY = { | ||
| name: "($self, /)" | ||
| for name in ( | ||
| "__repr__", "__hash__", "__neg__", "__pos__", "__abs__", "__bool__", | ||
| "conjugate", "__complex__", "__getnewargs__", | ||
| ) | ||
| } | ||
| EXPECTED = { | ||
| "__new__": "($type, *args, **kwargs)", | ||
| **VALUE_BINARY, | ||
| **SELF_ONLY, | ||
| "__pow__": "($self, value, mod=None, /)", | ||
| "__rpow__": "($self, value, mod=None, /)", | ||
| "from_number": "($type, number, /)", | ||
| "__format__": "($self, format_spec, /)", | ||
| } | ||
|
|
||
| for name, signature in EXPECTED.items(): | ||
| assert complex.__dict__[name].__text_signature__ == signature, name | ||
|
|
||
| assert str(inspect.signature(complex.from_number)) == "(number, /)" | ||
| assert str(inspect.signature(complex.__pow__)) == "(self, value, mod=None, /)" | ||
| assert str(inspect.signature(complex.conjugate)) == "(self, /)" | ||
|
|
||
| print("OK") | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| """Python 3.14 ``__sizeof__`` surface for dict and set-like types.""" | ||
|
|
||
| for typ in (dict, set, frozenset): | ||
| assert "__sizeof__" in typ.__dict__ | ||
| assert typ.__sizeof__.__text_signature__ == "($self, /)" | ||
|
|
||
| assert dict().__sizeof__() == 48 | ||
| assert {0: None}.__sizeof__() == 208 | ||
| assert {str(i): None for i in range(6)}.__sizeof__() == 256 | ||
| assert dict.fromkeys(range(11)).__sizeof__() == 616 | ||
|
|
||
| for typ in (set, frozenset): | ||
| assert typ().__sizeof__() == 200 | ||
| assert typ(range(4)).__sizeof__() == 200 | ||
| assert typ(range(5)).__sizeof__() == 712 | ||
| assert typ(range(19)).__sizeof__() == 2248 | ||
|
Comment on lines
+7
to
+16
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win Two parity fixtures hardcode 64-bit-specific integers. Both encode values that depend on the pointer width, so they fail on a 32-bit build and the runner attributes the failure to pyre rather than to the platform.
🧰 Tools🪛 Ruff (0.16.1)[warning] 7-7: Unnecessary Rewrite as a literal (C408) 📍 Affects 2 files
🤖 Prompt for AI Agents |
||
|
|
||
| print("OK") | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value
Replace the constant-valued dict comprehensions with
dict.fromkeys.Ruff reports C420 on both comprehensions. Each maps every key to the same constant string.
♻️ Proposed change
📝 Committable suggestion
🧰 Tools
🪛 Ruff (0.16.1)
[warning] 6-13: Unnecessary dict comprehension for iterable; use
dict.fromkeysinsteadReplace with
dict.fromkeys(iterable))(C420)
[warning] 14-20: Unnecessary dict comprehension for iterable; use
dict.fromkeysinsteadReplace with
dict.fromkeys(iterable))(C420)
🤖 Prompt for AI Agents
Source: Linters/SAST tools