Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #76259
| From | Terry Reedy <tjreedy@udel.edu> |
|---|---|
| Subject | Re: what is the "/" mean in __init__(self, /, *args, **kwargs) ? |
| Date | 2014-08-14 00:03 -0400 |
| References | <53EC1887.6060205@gmail.com> <53EC1CD6.4080203@stoneleaf.us> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.12967.1407989035.18130.python-list@python.org> (permalink) |
On 8/13/2014 10:20 PM, Ethan Furman wrote: > On 08/13/2014 07:01 PM, luofeiyu wrote: >>>>> help(int.__init__) >> Help on wrapper_descriptor: >> >> __init__(self, /, *args, **kwargs) >> Initialize self. See help(type(self)) for accurate signature. >> >> what is the "/" mean in __init__(self, /, *args, **kwargs) ? > > The '/' means that all arguments before it must be positional only. In particular, int.__init__(self = <subclass instance>) will not work because 'self' is positional only. (I don't think int.__init__ actually does anything, but a subclass of int might call it.) > This looks like an artifact of the new Argument Clinic for C code. > > For example, if this also worked at the Python level, you could say: > > def some_func(this, that, /, spam, eggs, *, foo, bar): > pass > > Meaning that the first two parameters could not be specified by name, > the next two could be either name or position, and the last two by name > only. > > Oh, and the * is valid Python now (the / is not -- it's solely a > documentation feature at this point). I hope / will be valid Python in 3.5. -- Terry Jan Reedy
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: what is the "/" mean in __init__(self, /, *args, **kwargs) ? Terry Reedy <tjreedy@udel.edu> - 2014-08-14 00:03 -0400
csiph-web