Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 33.9k
gh-104050: Add more type annotations to Argument Clinic#104631
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
erlend-aasland merged 8 commits into python:main from erlend-aasland:typed-clinic/more-classesMay 21, 2023
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
8 commits Select commit Hold shift + click to select a range
36ae292 gh-104050: Add more type annotations to Argument Clinic
erlend-aasland 4a6fdfe Pull in main
erlend-aasland d4055ea Pull in main
erlend-aasland 1da5282 Fix return converter
erlend-aasland ccd1bb6 WIP
erlend-aasland 3877c7b str does the trick?
erlend-aasland e239ab5 str does the trick again?
erlend-aasland 0ecd3a1 Partially revert Function.copy() annotation
erlend-aasland File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
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 |
|---|---|---|
| @@ -2395,6 +2395,9 @@ def __repr__(self) -> str: | ||
| INVALID, CALLABLE, STATIC_METHOD, CLASS_METHOD, METHOD_INIT, METHOD_NEW | ||
| """.replace(",", "").strip().split() | ||
| ParamDict = dict[str, "Parameter"] | ||
| ReturnConverterType = Callable[..., "CReturnConverter"] | ||
| class Function: | ||
| """ | ||
| Mutable duck type for inspect.Function. | ||
| @@ -2407,12 +2410,22 @@ class Function: | ||
| (not docstring) or ((not docstring[0].isspace()) and (docstring.rstrip() == docstring)) | ||
| """ | ||
| def __init__(self, parameters=None, *, name, | ||
| module, cls=None, c_basename=None, | ||
| full_name=None, | ||
| return_converter, return_annotation=inspect.Signature.empty, | ||
| docstring=None, kind=CALLABLE, coexist=False, | ||
| docstring_only=False): | ||
| def __init__( | ||
| self, | ||
| parameters: ParamDict | None = None, | ||
| *, | ||
| name: str, | ||
| module: Module, | ||
| cls: Class | None = None, | ||
| c_basename: str | None = None, | ||
| full_name: str | None = None, | ||
| return_converter: ReturnConverterType, | ||
| return_annotation = inspect.Signature.empty, | ||
| docstring: str | None = None, | ||
| kind: str = CALLABLE, | ||
| coexist: bool = False, | ||
| docstring_only: bool = False | ||
| ) -> None: | ||
| self.parameters = parameters or{} | ||
| self.return_annotation = return_annotation | ||
| self.name = name | ||
| @@ -2446,7 +2459,7 @@ def render_parameters(self): | ||
| return self.__render_parameters__ | ||
| @property | ||
| def methoddef_flags(self): | ||
| def methoddef_flags(self) -> str | None: | ||
| if self.kind in (METHOD_INIT, METHOD_NEW): | ||
| return None | ||
| flags = [] | ||
| @@ -2460,10 +2473,10 @@ def methoddef_flags(self): | ||
| flags.append('METH_COEXIST') | ||
| return '|'.join(flags) | ||
| def __repr__(self): | ||
| def __repr__(self) -> str: | ||
| return '<clinic.Function ' + self.name + '>' | ||
| def copy(self, **overrides): | ||
| def copy(self, **overrides) -> "Function": | ||
erlend-aasland marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading. Please reload this page. | ||
| kwargs ={ | ||
| 'name': self.name, 'module': self.module, 'parameters': self.parameters, | ||
| 'cls': self.cls, 'c_basename': self.c_basename, | ||
| @@ -2486,9 +2499,18 @@ class Parameter: | ||
| Mutable duck type of inspect.Parameter. | ||
| """ | ||
| def __init__(self, name, kind, *, default=inspect.Parameter.empty, | ||
| function, converter, annotation=inspect.Parameter.empty, | ||
| docstring=None, group=0): | ||
| def __init__( | ||
| self, | ||
| name: str, | ||
| kind: str, | ||
| *, | ||
| default = inspect.Parameter.empty, | ||
| function: Function, | ||
| converter: "CConverter", | ||
| annotation = inspect.Parameter.empty, | ||
| docstring: str | None = None, | ||
| group: int = 0 | ||
| ) -> None: | ||
| self.name = name | ||
| self.kind = kind | ||
| self.default = default | ||
| @@ -2498,22 +2520,22 @@ def __init__(self, name, kind, *, default=inspect.Parameter.empty, | ||
| self.docstring = docstring or '' | ||
| self.group = group | ||
| def __repr__(self): | ||
| def __repr__(self) -> str: | ||
| return '<clinic.Parameter ' + self.name + '>' | ||
| def is_keyword_only(self): | ||
| def is_keyword_only(self) -> bool: | ||
| return self.kind == inspect.Parameter.KEYWORD_ONLY | ||
| def is_positional_only(self): | ||
| def is_positional_only(self) -> bool: | ||
| return self.kind == inspect.Parameter.POSITIONAL_ONLY | ||
| def is_vararg(self): | ||
| def is_vararg(self) -> bool: | ||
| return self.kind == inspect.Parameter.VAR_POSITIONAL | ||
| def is_optional(self): | ||
| def is_optional(self) -> bool: | ||
| return not self.is_vararg() and (self.default is not unspecified) | ||
| def copy(self, **overrides): | ||
| def copy(self, **overrides) -> "Parameter": | ||
| kwargs ={ | ||
| 'name': self.name, 'kind': self.kind, 'default':self.default, | ||
| 'function': self.function, 'converter': self.converter, 'annotation': self.annotation, | ||
| @@ -2526,7 +2548,7 @@ def copy(self, **overrides): | ||
| kwargs['converter'] = converter | ||
| return Parameter(**kwargs) | ||
| def get_displayname(self, i): | ||
| def get_displayname(self, i: int) -> str: | ||
| if i == 0: | ||
| return '"argument"' | ||
| if not self.is_positional_only(): | ||
| @@ -2537,13 +2559,13 @@ def get_displayname(self, i): | ||
| class LandMine: | ||
| # try to access any | ||
| def __init__(self, message): | ||
| def __init__(self, message: str) -> None: | ||
| self.__message__ = message | ||
| def __repr__(self): | ||
| def __repr__(self) -> str: | ||
| return '<LandMine ' + repr(self.__message__) + ">" | ||
| def __getattribute__(self, name): | ||
| def __getattribute__(self, name: str): | ||
| if name in ('__repr__', '__message__'): | ||
| return super().__getattribute__(name) | ||
| # raise RuntimeError(repr(name)) | ||
| @@ -3002,7 +3024,6 @@ def parser_name(self): | ||
| # The callable may have any number of keyword-only parameters. | ||
| # The callable must return a CReturnConverter object. | ||
| # The callable should not call builtins.print. | ||
| ReturnConverterType = Callable[..., "CReturnConverter"] | ||
| ReturnConverterDict = dict[str, ReturnConverterType] | ||
| return_converters: ReturnConverterDict ={} | ||
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.