FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-104050: Add more type hints to Argument Clinic DSLParser() by erlend-aasland · Pull Request #106354 · python/cpython · GitHub

/ cpython Public
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension .py  (1) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
19 changes: 11 additions & 8 deletions Tools/clinic/clinic.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# Copyright 2012-2013 by Larry Hastings.
# Licensed to the PSF under a contributor agreement.
#
from __future__ import annotations

import abc
import ast
Expand Down Expand Up @@ -2448,7 +2449,7 @@ def __init__(
cls: Class | None = None,
c_basename: str | None = None,
full_name: str | None = None,
return_converter: ReturnConverterType,
return_converter: CReturnConverter,
return_annotation = inspect.Signature.empty,
docstring: str | None = None,
kind: str = CALLABLE,
Expand All @@ -2467,7 +2468,7 @@ def __init__(
self.docstring = docstring or ''
self.kind = kind
self.coexist = coexist
self.self_converter = None
self.self_converter: self_converter | None = None
# docstring_only means "don't generate a machine-readable
# signature, just a normal docstring". it's True for
# functions with optional groups because we can't represent
Expand Down Expand Up @@ -2531,7 +2532,7 @@ class Parameter:
def __init__(
self,
name: str,
kind: str,
kind: inspect._ParameterKind,
*,
default = inspect.Parameter.empty,
function: Function,
Expand Down Expand Up @@ -4539,7 +4540,7 @@ def state_dsl_start(self, line: str | None) -> None:

self.next(self.state_modulename_name, line)

def state_modulename_name(self, line):
def state_modulename_name(self, line: str | None) -> None:
# looking for declaration, which establishes the leftmost column
# line should be
# modulename.fnname [as c_basename] [-> return annotation]
Expand All @@ -4556,13 +4557,14 @@ def state_modulename_name(self, line):
# this line is permitted to start with whitespace.
# we'll call this number of spaces F (for "function").

if not line.strip():
if not self.valid_line(line):
return

self.indent.infer(line)

# are we cloning?
before, equals, existing = line.rpartition('=')
c_basename: str | None
if equals:
full_name, _, c_basename = before.partition(' as ')
full_name = full_name.strip()
Expand Down Expand Up @@ -4665,8 +4667,9 @@ def state_modulename_name(self, line):
if cls and type == "PyObject *":
kwargs['type'] = cls.typedef
sc = self.function.self_converter = self_converter(name, name, self.function, **kwargs)
p_self = Parameter(sc.name, inspect.Parameter.POSITIONAL_ONLY, function=self.function, converter=sc)
self.function.parameters[sc.name] = p_self
p_self = Parameter(name, inspect.Parameter.POSITIONAL_ONLY,
function=self.function, converter=sc)
self.function.parameters[name] = p_self

(cls or module).functions.append(self.function)
self.next(self.state_parameters_start)
Expand Down Expand Up @@ -4740,7 +4743,7 @@ def state_modulename_name(self, line):
ps_start, ps_left_square_before, ps_group_before, ps_required, \
ps_optional, ps_group_after, ps_right_square_after = range(7)

def state_parameters_start(self, line: str) -> None:
def state_parameters_start(self, line: str | None) -> None:
if not self.valid_line(line):
return

Expand Down

Back | FazBrowse Home | New Git URL