Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

gh-106706: Streamline family syntax #106716

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 39 commits into from
Jul 16, 2023
Merged
Changes from 1 commit
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
294750d
gh-106706 Streamline family syntax
kgdiem Jul 13, 2023
7dc364c
Update syntax in interpreter_definition.md
kgdiem Jul 13, 2023
dac8eb5
Further refactor bytecodes.c
kgdiem Jul 13, 2023
b05a7f8
Update test
kgdiem Jul 13, 2023
47f2491
Update syntax in interpreter_definition.md
kgdiem Jul 13, 2023
d499926
Update interpreter_definition to new syntax
kgdiem Jul 13, 2023
6fee03d
Use family name as first instruction
kgdiem Jul 13, 2023
d13dbf2
stop using slice in iters
kgdiem Jul 13, 2023
105871c
Remove formatting in interpreter_definition.md
kgdiem Jul 13, 2023
945f09d
Change test
kgdiem Jul 13, 2023
c4ffdc5
Merge branch 'main' into streamline-family-syntax
kgdiem Jul 13, 2023
b588c72
Fix check
kgdiem Jul 13, 2023
e091ca3
Fix assertion
kgdiem Jul 13, 2023
59dedfe
📜🤖 Added by blurb_it.
blurb-it[bot] Jul 13, 2023
868ae1b
lint blurb
kgdiem Jul 13, 2023
ae5cd52
Merge branch 'main' into streamline-family-syntax
kgdiem Jul 13, 2023
843880d
Update Misc/NEWS.d/next/Tools-Demos/2023-07-13-12-08-35.gh-issue-1067…
kgdiem Jul 14, 2023
906c8b2
Remove redundant checks for family member length
kgdiem Jul 14, 2023
c367600
Reword documentation
kgdiem Jul 14, 2023
d31258c
Update test, regenerate headers
kgdiem Jul 14, 2023
9986c2e
keep formatting in interpreter_definiton
kgdiem Jul 14, 2023
1601141
GH-104909: Split `LOAD_ATTR_INSTANCE_VALUE` into micro-ops (GH-106678)
markshannon Jul 13, 2023
8ce84bc
gh-106690: Add a .coveragerc file to the CPython repository (#8150)
ammaraskar Jul 13, 2023
ca8147a
gh-106701: Move the hand-written Tier 2 uops to bytecodes.c (#106702)
gvanrossum Jul 13, 2023
58025d6
gh-106664: selectors: add get() method to _SelectorMapping (#106665)
bdraco Jul 13, 2023
fd9f8d6
docs: clarify Path.suffix (GH-106650)
nedbat Jul 13, 2023
9acddfa
gh-106368: Increase Argument Clinic test coverage (#106728)
erlend-aasland Jul 13, 2023
0941a94
gh-104683: Argument clinic: use an enum to describe the different kin…
AlexWaygood Jul 13, 2023
c15f572
gh-106529: Split FOR_ITER_{LIST,TUPLE} into uops (#106696)
gvanrossum Jul 14, 2023
656c5bc
gh-105626: Change the default return value of `HTTPConnection.get_pro…
sobolevn Jul 14, 2023
642cc0e
gh-105293: Do not call SSL_CTX_set_session_id_context on client side …
grantramsay Jul 14, 2023
2dd5049
gh-106446: Fix failed doctest in stdtypes (#106447)
CharlieZhao95 Jul 14, 2023
ea05f4d
Fix check
kgdiem Jul 13, 2023
178e300
Merge branch 'main' into streamline-family-syntax
erlend-aasland Jul 14, 2023
eab1974
Regen cases
kgdiem Jul 15, 2023
1e68564
Check against family name when emitting cache size check, add family.…
kgdiem Jul 16, 2023
85cbbed
update family syntax in test
kgdiem Jul 16, 2023
82a9927
Regenerate cases
kgdiem Jul 16, 2023
b05e24d
Check families for mac.name instead of last_instr.family
kgdiem Jul 16, 2023
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
gh-104683: Argument clinic: use an enum to describe the different kin…
…ds of functions (#106721)

Argument clinic: use an enum to describe the different kinds of functions
  • Loading branch information
AlexWaygood authored and kgdiem committed Jul 14, 2023
commit 0941a94187803b99a93fef352d191fdb9db047fc
69 changes: 44 additions & 25 deletions 69 Tools/clinic/clinic.py
Original file line number Diff line number Diff line change
Expand Up @@ -807,7 +807,7 @@ def output_templates(self, f):
default_return_converter = (not f.return_converter or
f.return_converter.type == 'PyObject *')

new_or_init = f.kind in (METHOD_NEW, METHOD_INIT)
new_or_init = f.kind.new_or_init

vararg = NO_VARARG
pos_only = min_pos = max_pos = min_kw_only = pseudo_args = 0
Expand Down Expand Up @@ -1250,7 +1250,7 @@ def parser_body(
if new_or_init:
methoddef_define = ''

if f.kind == METHOD_NEW:
if f.kind is METHOD_NEW:
parser_prototype = parser_prototype_keyword
else:
return_value_declaration = "int return_value = -1;"
Expand Down Expand Up @@ -1475,7 +1475,7 @@ def render_function(
last_group = 0
first_optional = len(selfless)
positional = selfless and selfless[-1].is_positional_only()
new_or_init = f.kind in (METHOD_NEW, METHOD_INIT)
new_or_init = f.kind.new_or_init
has_option_groups = False

# offset i by -1 because first_optional needs to ignore self
Expand Down Expand Up @@ -2441,9 +2441,28 @@ def __repr__(self) -> str:
""".strip().split())


INVALID, CALLABLE, STATIC_METHOD, CLASS_METHOD, METHOD_INIT, METHOD_NEW = """
INVALID, CALLABLE, STATIC_METHOD, CLASS_METHOD, METHOD_INIT, METHOD_NEW
""".replace(",", "").strip().split()
class FunctionKind(enum.Enum):
INVALID = enum.auto()
CALLABLE = enum.auto()
STATIC_METHOD = enum.auto()
CLASS_METHOD = enum.auto()
METHOD_INIT = enum.auto()
METHOD_NEW = enum.auto()

@functools.cached_property
def new_or_init(self) -> bool:
return self in {FunctionKind.METHOD_INIT, FunctionKind.METHOD_NEW}

def __repr__(self) -> str:
return f"<FunctionKind.{self.name}>"


INVALID: Final = FunctionKind.INVALID
CALLABLE: Final = FunctionKind.CALLABLE
STATIC_METHOD: Final = FunctionKind.STATIC_METHOD
CLASS_METHOD: Final = FunctionKind.CLASS_METHOD
METHOD_INIT: Final = FunctionKind.METHOD_INIT
METHOD_NEW: Final = FunctionKind.METHOD_NEW

ParamDict = dict[str, "Parameter"]
ReturnConverterType = Callable[..., "CReturnConverter"]
Expand Down Expand Up @@ -2471,7 +2490,7 @@ class Function:
return_converter: CReturnConverter
return_annotation: object = inspect.Signature.empty
docstring: str = ''
kind: str = CALLABLE
kind: FunctionKind = CALLABLE
coexist: bool = False
# docstring_only means "don't generate a machine-readable
# signature, just a normal docstring". it's True for
Expand All @@ -2497,15 +2516,16 @@ def render_parameters(self) -> list[Parameter]:

@property
def methoddef_flags(self) -> str | None:
if self.kind in (METHOD_INIT, METHOD_NEW):
if self.kind.new_or_init:
return None
flags = []
if self.kind == CLASS_METHOD:
flags.append('METH_CLASS')
elif self.kind == STATIC_METHOD:
flags.append('METH_STATIC')
else:
assert self.kind == CALLABLE, "unknown kind: " + repr(self.kind)
match self.kind:
case FunctionKind.CLASS_METHOD:
flags.append('METH_CLASS')
case FunctionKind.STATIC_METHOD:
flags.append('METH_STATIC')
case _ as kind:
assert kind is FunctionKind.CALLABLE, f"unknown kind: {kind!r}"
if self.coexist:
flags.append('METH_COEXIST')
return '|'.join(flags)
Expand Down Expand Up @@ -3888,7 +3908,7 @@ def correct_name_for_self(
if f.cls:
return "PyObject *", "self"
return "PyObject *", "module"
if f.kind == STATIC_METHOD:
if f.kind is STATIC_METHOD:
return "void *", "null"
if f.kind in (CLASS_METHOD, METHOD_NEW):
return "PyTypeObject *", "type"
Expand Down Expand Up @@ -3921,9 +3941,8 @@ def pre_render(self):
self.type = self.specified_type or self.type or default_type

kind = self.function.kind
new_or_init = kind in (METHOD_NEW, METHOD_INIT)

if (kind == STATIC_METHOD) or new_or_init:
if kind is STATIC_METHOD or kind.new_or_init:
self.show_in_signature = False

# tp_new (METHOD_NEW) functions are of type newfunc:
Expand Down Expand Up @@ -3973,7 +3992,7 @@ def render(self, parameter, data):
parameter is a clinic.Parameter instance.
data is a CRenderData instance.
"""
if self.function.kind == STATIC_METHOD:
if self.function.kind is STATIC_METHOD:
return

self._render_self(parameter, data)
Expand All @@ -3992,8 +4011,8 @@ def set_template_dict(self, template_dict):
kind = self.function.kind
cls = self.function.cls

if ((kind in (METHOD_NEW, METHOD_INIT)) and cls and cls.typedef):
if kind == METHOD_NEW:
if kind.new_or_init and cls and cls.typedef:
if kind is METHOD_NEW:
type_check = (
'({0} == base_tp || {0}->tp_init == base_tp->tp_init)'
).format(self.name)
Expand Down Expand Up @@ -4337,7 +4356,7 @@ class DSLParser:
parameter_state: int
seen_positional_with_default: bool
indent: IndentStack
kind: str
kind: FunctionKind
coexist: bool
parameter_continuation: str
preserve_output: bool
Expand Down Expand Up @@ -4626,7 +4645,7 @@ def state_modulename_name(self, line: str | None) -> None:
function_name = fields.pop()
module, cls = self.clinic._module_and_class(fields)

if not (existing_function.kind == self.kind and existing_function.coexist == self.coexist):
if not (existing_function.kind is self.kind and existing_function.coexist == self.coexist):
fail("'kind' of function and cloned function don't match! (@classmethod/@staticmethod/@coexist)")
function = existing_function.copy(
name=function_name, full_name=full_name, module=module,
Expand Down Expand Up @@ -4679,11 +4698,11 @@ def state_modulename_name(self, line: str | None) -> None:
fail(f"{fields[-1]} is a special method and cannot be converted to Argument Clinic! (Yet.)")

if fields[-1] == '__new__':
if (self.kind != CLASS_METHOD) or (not cls):
if (self.kind is not CLASS_METHOD) or (not cls):
fail("__new__ must be a class method!")
self.kind = METHOD_NEW
elif fields[-1] == '__init__':
if (self.kind != CALLABLE) or (not cls):
if (self.kind is not CALLABLE) or (not cls):
fail("__init__ must be a normal method, not a class or static method!")
self.kind = METHOD_INIT
if not return_converter:
Expand Down Expand Up @@ -5203,7 +5222,7 @@ def state_function_docstring(self, line):
def format_docstring(self):
f = self.function

new_or_init = f.kind in (METHOD_NEW, METHOD_INIT)
new_or_init = f.kind.new_or_init
if new_or_init and not f.docstring:
# don't render a docstring at all, no signature, nothing.
return f.docstring
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.