Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.7k
gh-107805: Fix signatures of module-level generated functions inturtle#107807
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes from1 commit
40ee61d03ea67d7f71ffd43f131f51f5bf0438dcbcac50e7fFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
…tle`
- Loading branch information
Uh oh!
There was an error while loading.Please reload this page.
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -461,5 +461,32 @@ def test_teleport(self): | ||
| self.assertTrue(tpen.isdown()) | ||
| class TestModuleLevel(unittest.TestCase): | ||
| def test_all_signatures(self): | ||
| import inspect | ||
| import types | ||
| known_signatures = { | ||
| 'teleport': | ||
| '(x=None, y=None, fill_gap: bool = False) -> None', | ||
| 'clear': '()', | ||
| 'reset': '(canvwidth=None, canvheight=None, bg=None)', | ||
| 'bgcolor': '(*args)', | ||
| 'pen': '(pen=None, **pendict)', | ||
| } | ||
| for name in turtle.__all__: | ||
| ||
| obj = getattr(turtle, name) | ||
| if not isinstance(obj, types.FunctionType): | ||
| continue | ||
| with self.subTest(name=name): | ||
| # All functions must produce correct signatures: | ||
| sig = inspect.signature(obj) | ||
| if name in known_signatures: | ||
| self.assertEqual(str(sig), known_signatures[name]) | ||
| if __name__ == '__main__': | ||
| unittest.main() | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -3920,28 +3920,31 @@ def getmethparlist(ob): | ||
| function definition and the second is suitable for use in function | ||
| call. The "self" parameter is not included. | ||
| """ | ||
| orig_sig =inspect.signature(ob) | ||
| # bit of a hack for methods - turn it into a function | ||
| # but we drop the "self" param. | ||
| # Try and build one for Python defined functions | ||
| func_sig = orig_sig.replace( | ||
| parameters=list(orig_sig.parameters.values())[1:], | ||
| ) | ||
| call_args = [] | ||
| for param in func_sig.parameters.values(): | ||
| kind = param.kind | ||
| if kind in ( | ||
| inspect.Parameter.POSITIONAL_ONLY, | ||
| inspect.Parameter.POSITIONAL_OR_KEYWORD, | ||
| ): | ||
| call_args.append(param.name) | ||
| if kind == inspect.Parameter.VAR_POSITIONAL: | ||
sobolevn marked this conversation as resolved. OutdatedShow resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| call_args.append(f'*{param.name}') | ||
| if kind == inspect.Parameter.KEYWORD_ONLY: | ||
| call_args.append(f'{param.name}={param.name}') | ||
| if kind == inspect.Parameter.VAR_KEYWORD: | ||
| call_args.append(f'**{param.name}') | ||
| call_text = f'({', '.join(call_args)})' | ||
| return str(func_sig), call_text | ||
| def _turtle_docrevise(docstr): | ||
| """To reduce docstrings from RawTurtle class for functions | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Fix signatures of module-level generated functions in :mod:`turtle`. |