|
149 | 149 | import types
|
150 | 150 | import functools
|
151 | 151 | import builtins
|
| 152 | +from keyword import iskeyword |
152 | 153 | from operator import attrgetter
|
153 | 154 | from collections import namedtuple, OrderedDict
|
154 | 155 |
|
@@ -1645,7 +1646,7 @@ def __new__(cls, filename, lineno, function, code_context, index, *, positions=N
|
1645 | 1646 | instance = super().__new__(cls, filename, lineno, function, code_context, index)
|
1646 | 1647 | instance.positions = positions
|
1647 | 1648 | return instance
|
1648 |
| - |
| 1649 | + |
1649 | 1650 | def __repr__(self):
|
1650 | 1651 | return ('Traceback(filename={!r}, lineno={!r}, function={!r}, '
|
1651 | 1652 | 'code_context={!r}, index={!r}, positions={!r})'.format(
|
@@ -1683,7 +1684,7 @@ def getframeinfo(frame, context=1):
|
1683 | 1684 | frame, *positions = (frame, lineno, *positions[1:])
|
1684 | 1685 | else:
|
1685 | 1686 | frame, *positions = (frame, *positions)
|
1686 |
| - |
| 1687 | + |
1687 | 1688 | lineno = positions[0]
|
1688 | 1689 |
|
1689 | 1690 | if not isframe(frame):
|
@@ -2707,7 +2708,10 @@ def __init__(self, name, kind, *, default=_empty, annotation=_empty):
|
2707 | 2708 | self._kind = _POSITIONAL_ONLY
|
2708 | 2709 | name = 'implicit{}'.format(name[1:])
|
2709 | 2710 |
|
2710 |
| - if not name.isidentifier(): |
| 2711 | + # It's possible for C functions to have a positional-only parameter |
| 2712 | + # where the name is a keyword, so for compatibility we'll allow it. |
| 2713 | + is_keyword = iskeyword(name) and self._kind is not _POSITIONAL_ONLY |
| 2714 | + if is_keyword or not name.isidentifier(): |
2711 | 2715 | raise ValueError('{!r} is not a valid parameter name'.format(name))
|
2712 | 2716 |
|
2713 | 2717 | self._name = name
|
|
0 commit comments