[issue20144] Argument Clinic doesn't support named constants as default values

2014-01-07 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: Thank you Larry for all your fixes. -- ___ Python tracker ___ ___ Python-bugs-list mailing list Un

[issue20144] Argument Clinic doesn't support named constants as default values

2014-01-07 Thread Larry Hastings
Larry Hastings added the comment: Argument Clinic now supports simple constants like "sys.maxsize" as default values for arguments for builtins. I'm assuming this gets you basically what you wanted; if this isn't sufficient please open a new issue. -- assignee: -> larry resolution:

[issue20144] Argument Clinic doesn't support named constants as default values

2014-01-07 Thread Roundup Robot
Roundup Robot added the comment: New changeset c96dba33f019 by Larry Hastings in branch 'default': Issue #20144: Argument Clinic now supports simple constants as parameter http://hg.python.org/cpython/rev/c96dba33f019 -- nosy: +python-dev ___ Python t

[issue20144] Argument Clinic doesn't support named constants as default values

2014-01-07 Thread Larry Hastings
Larry Hastings added the comment: Incorporated suggestions from Serhiy. Thanks, Serhiy! -- Added file: http://bugs.python.org/file33348/larry.simple.symbolic.constant.default.values.diff.4.txt ___ Python tracker

[issue20144] Argument Clinic doesn't support named constants as default values

2014-01-07 Thread Larry Hastings
Larry Hastings added the comment: At Antoine's suggestion, I added a custom function to testcapi that exercises all the different possible types for default values in a text signature. Also the docs have been updated. LGTU? -- Added file: http://bugs.python.org/file33344/larry.simpl

[issue20144] Argument Clinic doesn't support named constants as default values

2014-01-07 Thread Larry Hastings
Larry Hastings added the comment: Oops! I forgot to actually attach the new patch. I'm dumb. -- Added file: http://bugs.python.org/file33340/larry.simple.symbolic.constant.default.values.diff.2.txt ___ Python tracker

[issue20144] Argument Clinic doesn't support named constants as default values

2014-01-07 Thread Larry Hastings
Larry Hastings added the comment: Here's a second patch; I think this is ready to go in I cleaned up the node parsing a lot. It now knows how to parse the following types of default values: * Number (this applies to both ints and floats) * String ('hello') * Attribute (sys.maxsize) * N

[issue20144] Argument Clinic doesn't support named constants as default values

2014-01-06 Thread Larry Hastings
Larry Hastings added the comment: storchaka: You propose a result, not an approach. How do you propose we do that? In any case, I think making *that* work would be way too big a change for 3.4. Whatever you proposed would only be appropriate for 3.5. --

[issue20144] Argument Clinic doesn't support named constants as default values

2014-01-06 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: I proposed contrary approach. Allow docstring to fake signature. >>> import sys >>> import inspect >>> def foo(blah=sys.maxsize): "foo(blah=sys.maxsize)" pass ... >>> str(inspect.signature(foo)) '(blah=sys.maxsi

[issue20144] Argument Clinic doesn't support named constants as default values

2014-01-06 Thread Antoine Pitrou
Changes by Antoine Pitrou : -- nosy: +ncoghlan ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.pyt

[issue20144] Argument Clinic doesn't support named constants as default values

2014-01-06 Thread Larry Hastings
Larry Hastings added the comment: Attached is a patch supporting simple symbolic constants. It works from beginning to end--you specify it in the Argument Clinic input and it shows up in the inspect.Signature and uses the constant in the generated C code. One complication: when using one of t

[issue20144] Argument Clinic doesn't support named constants as default values

2014-01-06 Thread Barry A. Warsaw
Barry A. Warsaw added the comment: On Jan 06, 2014, at 08:23 PM, Larry Hastings wrote: >Could you live with this being checked in to 3.4? For sure! -- ___ Python tracker ___ __

[issue20144] Argument Clinic doesn't support named constants as default values

2014-01-06 Thread Larry Hastings
Larry Hastings added the comment: It is unfortunate, but on the other hand that's what happens in Python too: >>> import sys >>> import inspect >>> def foo(blah=sys.maxsize): pass ... >>> str(inspect.signature(foo)) '(blah=9223372036854775807)' Nick proposed something w

[issue20144] Argument Clinic doesn't support named constants as default values

2014-01-06 Thread Barry A. Warsaw
Barry A. Warsaw added the comment: It seems a little unfortunate that you lose the symbolic default, especially since the expanded number just appears random. >>> print(inspect.signature(os.stat)) (path, *, dir_fd=None, follow_symlinks=True, fake=9223372036854775807) >>> sys.maxsize 92233720368

[issue20144] Argument Clinic doesn't support named constants as default values

2014-01-06 Thread Larry Hastings
Larry Hastings added the comment: Whoops, forgot to attach the file. here it is. -- Added file: http://bugs.python.org/file1/larry.simple.named.constants.in.text.signature.example ___ Python tracker _

[issue20144] Argument Clinic doesn't support named constants as default values

2014-01-06 Thread Larry Hastings
Larry Hastings added the comment: Attached is an example of how we could support simple named constants in __text_signature__. The change to posixmodule.c is just a hack to exercise the code in inspect.Signature; I didn't have a good example handy. When I apply the patch and run "x.py", I see

[issue20144] Argument Clinic doesn't support named constants as default values

2014-01-06 Thread Jeremy Kloth
Changes by Jeremy Kloth : -- nosy: +jkloth ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.

[issue20144] Argument Clinic doesn't support named constants as default values

2014-01-06 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: Then perhaps these methods can not be converted to use Argument Clinic now. -- ___ Python tracker ___

[issue20144] Argument Clinic doesn't support named constants as default values

2014-01-06 Thread Larry Hastings
Larry Hastings added the comment: "sys.maxsize" won't work. inspect.Signature parses the __text_signature__ using ast.parse, and it only recognizes constant values and named constants (True/False/None) for the default value for parameters. Playing with ast, it looks like we'd have to support

[issue20144] Argument Clinic doesn't support named constants as default values

2014-01-06 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: Not always default value can be expressed in Python. Current docstring for the match() method says "match(string[, pos[, endpos]])". For this particular case it can be written as "match(string, pos=0, endpos=sys.maxsize)". And this is very common case (see a

[issue20144] Argument Clinic doesn't support named constants as default values

2014-01-06 Thread Larry Hastings
Larry Hastings added the comment: As an example, consider pattern_match() in _sre.c. This implements the match method on a pattern object; in other words, re.compile().match(). The third parameter, endpos, defaults to PY_SSIZE_T_MAX in C. What should inspect.Signature() report as the defaul

[issue20144] Argument Clinic doesn't support named constants as default values

2014-01-06 Thread Larry Hastings
Larry Hastings added the comment: Here's the problem. Let's say I gave you a way of specifying a symbolic constant for the default value for C. What value should we use for the default value in Python? Keep in mind, it has to be expressed as a static value that can be stored as a string as

[issue20144] Argument Clinic doesn't support named constants as default values

2014-01-06 Thread Serhiy Storchaka
New submission from Serhiy Storchaka: For example it doesn't support PY_SSIZE_T_MAX as default value for Py_ssize_t argument. Is there any way to specify it? This is required for converting the _sre module. -- components: Build messages: 207435 nosy: larry, serhiy.storchaka priority: n