Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(16)

Unified Diff: Lib/inspect.py

Issue 10639: reindent.py converts newlines to platform default
Patch Set: Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Lib/importlib/test/source/test_file_loader.py ('k') | Lib/lib2to3/fixer_base.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
--- a/Lib/inspect.py Tue Jul 26 09:37:46 2011 +0300
+++ b/Lib/inspect.py Mon Jul 25 09:47:18 2011 -0400
@@ -33,6 +33,7 @@
import os
import types
import itertools
+import string
import re
import imp
import tokenize
@@ -917,24 +918,10 @@
specs.append(formatvarkw(varkw) + formatvalue(locals[varkw]))
return '(' + ', '.join(specs) + ')'
-def _missing_arguments(f_name, argnames, pos, values):
- names = [repr(name) for name in argnames if name not in values]
- missing = len(names)
- if missing == 1:
- s = names[0]
- elif missing == 2:
- s = "{} and {}".format(*names)
- else:
- tail = ", {} and {}".format(names[-2:])
- del names[-2:]
- s = ", ".join(names) + tail
- raise TypeError("%s() missing %i required %s argument%s: %s" %
- (f_name, missing,
- "positional" if pos else "keyword-only",
- "" if missing == 1 else "s", s))
-
-def _too_many(f_name, args, kwonly, varargs, defcount, given, values):
+def _positional_error(f_name, args, kwonly, varargs, defcount, given, values):
atleast = len(args) - defcount
+ if given is None:
+ given = len([arg for arg in args if arg in values])
kwonly_given = len([arg for arg in kwonly if arg in values])
if varargs:
plural = atleast != 1
@@ -993,25 +980,22 @@
(f_name, kw))
arg2value[kw] = value
if num_pos > num_args and not varargs:
- _too_many(f_name, args, kwonlyargs, varargs, num_defaults,
- num_pos, arg2value)
+ _positional_error(f_name, args, kwonlyargs, varargs, num_defaults,
+ num_pos, arg2value)
if num_pos < num_args:
- req = args[:num_args - num_defaults]
- for arg in req:
+ for arg in args[:num_args - num_defaults]:
if arg not in arg2value:
- _missing_arguments(f_name, req, True, arg2value)
+ _positional_error(f_name, args, kwonlyargs, varargs,
+ num_defaults, None, arg2value)
for i, arg in enumerate(args[num_args - num_defaults:]):
if arg not in arg2value:
arg2value[arg] = defaults[i]
- missing = 0
for kwarg in kwonlyargs:
if kwarg not in arg2value:
- if kwarg in kwonlydefaults:
- arg2value[kwarg] = kwonlydefaults[kwarg]
- else:
- missing += 1
- if missing:
- _missing_arguments(f_name, kwonlyargs, False, arg2value)
+ if kwarg not in kwonlydefaults:
+ raise TypeError("%s() requires keyword-only argument %r" %
+ (f_name, kwarg))
+ arg2value[kwarg] = kwonlydefaults[kwarg]
return arg2value
# -------------------------------------------------- stack frame extraction
« no previous file with comments | « Lib/importlib/test/source/test_file_loader.py ('k') | Lib/lib2to3/fixer_base.py » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+