Commit 78329d0
Speed up inspect.signature() for Python functions
For real Python functions the parameter kinds and defaults come straight
from the code object, so the validation done by Parameter.__init__ is
redundant. Construct the Parameter objects directly, falling back to the
regular constructor for names that are not plain identifiers (e.g. the
".0" implicit argument of comprehensions). Parameter subclasses and
duck-typed functions keep the full validation.
inspect.signature() on a function with 7 parameters: 23.4 us -> 14.5 us.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>1 parent 9bd9c74 commit 78329d0
2 files changed
Lines changed: 35 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2348 | 2348 | | |
2349 | 2349 | | |
2350 | 2350 | | |
| 2351 | + | |
| 2352 | + | |
2351 | 2353 | | |
2352 | 2354 | | |
2353 | 2355 | | |
| |||
2835 | 2837 | | |
2836 | 2838 | | |
2837 | 2839 | | |
| 2840 | + | |
| 2841 | + | |
| 2842 | + | |
| 2843 | + | |
| 2844 | + | |
| 2845 | + | |
| 2846 | + | |
| 2847 | + | |
| 2848 | + | |
| 2849 | + | |
| 2850 | + | |
| 2851 | + | |
| 2852 | + | |
| 2853 | + | |
| 2854 | + | |
| 2855 | + | |
| 2856 | + | |
| 2857 | + | |
| 2858 | + | |
2838 | 2859 | | |
2839 | 2860 | | |
2840 | 2861 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5656 | 5656 | | |
5657 | 5657 | | |
5658 | 5658 | | |
| 5659 | + | |
| 5660 | + | |
| 5661 | + | |
| 5662 | + | |
| 5663 | + | |
| 5664 | + | |
| 5665 | + | |
| 5666 | + | |
| 5667 | + | |
| 5668 | + | |
| 5669 | + | |
| 5670 | + | |
| 5671 | + | |
| 5672 | + | |
5659 | 5673 | | |
5660 | 5674 | | |
5661 | 5675 | | |
| |||
0 commit comments