<div dir="ltr"><div class="gmail_default" style="font-family:trebuchet ms,sans-serif">I am moving the discussion on file-like methods to GitHub. Mailing list is not very usable IMHO. Please switch to that.</div><div class="gmail_default" style="font-family:trebuchet ms,sans-serif"><br></div><div class="gmail_default" style="font-family:trebuchet ms,sans-serif"><a href="https://github.com/python/peps/issues/66">https://github.com/python/peps/issues/66</a><br></div></div><div class="gmail_extra"><br clear="all"><div><div class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div><div><font face="'trebuchet ms', sans-serif">pozdrawiam,</font></div><div><font face="'trebuchet ms', sans-serif">Arkadiusz Bulski</font></div><br></div></div></div></div></div></div></div>
<br><div class="gmail_quote">2016-08-02 7:02 GMT+02:00  <span dir="ltr"><<a href="mailto:python-ideas-request@python.org" target="_blank">python-ideas-request@python.org</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Send Python-ideas mailing list submissions to<br>
        <a href="mailto:python-ideas@python.org">python-ideas@python.org</a><br>
<br>
To subscribe or unsubscribe via the World Wide Web, visit<br>
        <a href="https://mail.python.org/mailman/listinfo/python-ideas" target="_blank" rel="noreferrer">https://mail.python.org/mailman/listinfo/python-ideas</a><br>
or, via email, send a message with subject or body 'help' to<br>
        <a href="mailto:python-ideas-request@python.org">python-ideas-request@python.org</a><br>
<br>
You can reach the person managing the list at<br>
        <a href="mailto:python-ideas-owner@python.org">python-ideas-owner@python.org</a><br>
<br>
When replying, please edit your Subject line so it is more specific<br>
than "Re: Contents of Python-ideas digest..."<br>
<br>
<br>
Today's Topics:<br>
<br>
   1. Re: Trial balloon: adding variable type declarations in<br>
      support of PEP 484 (Steven D'Aprano)<br>
   2. Re: Trial balloon: adding variable type declarations in<br>
      support of PEP 484 (Steven D'Aprano)<br>
   3. Re: Proposing new file-like object methods (eryk sun)<br>
   4. Re: Trial balloon: adding variable type declarations in<br>
      support of PEP 484 (Guido van Rossum)<br>
   5. Re: Trial balloon: adding variable type declarations in<br>
      support of PEP 484 (Guido van Rossum)<br>
<br>
<br>
----------------------------------------------------------------------<br>
<br>
Message: 1<br>
Date: Tue, 2 Aug 2016 12:55:09 +1000<br>
From: Steven D'Aprano <<a href="mailto:steve@pearwood.info">steve@pearwood.info</a>><br>
To: <a href="mailto:python-ideas@python.org">python-ideas@python.org</a><br>
Subject: Re: [Python-ideas] Trial balloon: adding variable type<br>
        declarations in support of PEP 484<br>
Message-ID: <<a href="mailto:20160802025509.GD6608@ando.pearwood.info">20160802025509.GD6608@ando.pearwood.info</a>><br>
Content-Type: text/plain; charset=us-ascii<br>
<br>
On Mon, Aug 01, 2016 at 02:31:16PM -0700, Guido van Rossum wrote:<br>
> PEP 484 doesn't change Python's syntax. Therefore it has no good<br>
> syntax to offer for declaring the type of variables, and instead you<br>
> have to write e.g.<br>
><br>
> a = 0  # type: float<br>
> b = []  # type: List[int]<br>
> c = None  # type: Optional[str]<br>
><br>
> I'd like to address this in the future, and I think the most elegant<br>
> syntax would be to let you write these as follows:<br>
><br>
> a: float = 0<br>
> b: List[int] = []<br>
> c: Optional[str] = None<br>
<br>
<br>
Those examples look reasonable to me.<br>
<br>
<br>
[...]<br>
> Second, when these occur in a class body, they can define either class<br>
> variables or instance variables. Do we need to be able to specify<br>
> which?<br>
<br>
I would think so. Consider the case that you have Class.spam and<br>
Class().spam which may not be the same type. E.g. the class attribute<br>
(representing the default value used by all instances) might be a<br>
mandatory int, while the instance attribute might be Optional[int].<br>
<br>
<br>
> Third, there's an annoying thing with tuples/commas here. On the one<br>
> hand, in a function declaration, we may see (a: int = 0, b: str = '').<br>
> On the other hand, in an assignment, we may see<br>
><br>
> a, b = 0, ''<br>
><br>
> Suppose we wanted to add types to the latter. Would we write this as<br>
><br>
> a, b: int, str = 0, ''<br>
><br>
> or as<br>
><br>
> a: int, b: str = 0, ''<br>
<br>
Require parens around the name:hint.<br>
<br>
(a:int), (b:str) = 0, ''<br>
<br>
Or just stick to a type hinting comment :-)<br>
<br>
<br>
What about this case?<br>
<br>
spam, eggs = [1, 2.0, 'foo'], (1, '')<br>
[a, b, c], [d, e] = spam, eggs<br>
<br>
That becomes:<br>
<br>
[(a:int), (b:float), (c:str)], [(x:int), (y:str)] = spam, eggs<br>
<br>
which is bearable, but just unpleasant enough to discourage people from<br>
doing it unless they really need to.<br>
<br>
<br>
--<br>
Steve<br>
<br>
<br>
------------------------------<br>
<br>
Message: 2<br>
Date: Tue, 2 Aug 2016 12:57:12 +1000<br>
From: Steven D'Aprano <<a href="mailto:steve@pearwood.info">steve@pearwood.info</a>><br>
To: <a href="mailto:python-ideas@python.org">python-ideas@python.org</a><br>
Subject: Re: [Python-ideas] Trial balloon: adding variable type<br>
        declarations in support of PEP 484<br>
Message-ID: <<a href="mailto:20160802025711.GE6608@ando.pearwood.info">20160802025711.GE6608@ando.pearwood.info</a>><br>
Content-Type: text/plain; charset=us-ascii<br>
<br>
On Tue, Aug 02, 2016 at 07:40:39AM +1000, Chris Angelico wrote:<br>
<br>
> Additional case, unless it's patently obvious to someone with more 484<br>
> experience than I: what happens with chained assignment?<br>
><br>
> a = b = c = 0<br>
><br>
> Does each variable get separately tagged, or does one tag apply to all?<br>
<br>
(a:int) = (b:Optional[int]) = c = 0<br>
<br>
`a` is declared to always be an int, `b` declared to be an int or None,<br>
and `c` is not declared.<br>
<br>
<br>
<br>
--<br>
Steve<br>
<br>
<br>
------------------------------<br>
<br>
Message: 3<br>
Date: Tue, 2 Aug 2016 04:33:53 +0000<br>
From: eryk sun <<a href="mailto:eryksun@gmail.com">eryksun@gmail.com</a>><br>
To: <a href="mailto:python-ideas@python.org">python-ideas@python.org</a><br>
Subject: Re: [Python-ideas] Proposing new file-like object methods<br>
Message-ID:<br>
        <<a href="mailto:CACL%2B1au%2BbX_tKQvxDJC1SBLSObKbqAUPjj9dpmcr9s1izq0Cng@mail.gmail.com">CACL+1au+bX_tKQvxDJC1SBLSObKbqAUPjj9dpmcr9s1izq0Cng@mail.gmail.com</a>><br>
Content-Type: text/plain; charset=UTF-8<br>
<br>
On Tue, Aug 2, 2016 at 2:00 AM, Random832 <<a href="mailto:random832@fastmail.com">random832@fastmail.com</a>> wrote:<br>
> On Mon, Aug 1, 2016, at 20:27, Wes Turner wrote:<br>
>> file.pread?<br>
><br>
> Wouldn't that be rather like having os.fstatat?<br>
><br>
> For the concept in general, I'm concerned that the equivalent<br>
> functionality on windows may require that the I/O be done<br>
> asynchronously, or that the file have been opened in a special<br>
> way.<br>
<br>
Updating the file position is all or nothing. In synchronous mode,<br>
which is what the CRT's low I/O implementation uses, the file position<br>
is always updated. However, one can atomically set the file position<br>
before a read by passing an overlapped with an offset to ReadFile,<br>
which in turn sets the ByteOffset argument of the underlying<br>
NtReadFile [1] system call.<br>
<br>
[1]: <a href="https://msdn.microsoft.com/en-us/library/ff567072" target="_blank" rel="noreferrer">https://msdn.microsoft.com/en-us/library/ff567072</a><br>
<br>
For example:<br>
<br>
    import _winapi<br>
    import ctypes<br>
    from ctypes import wintypes<br>
<br>
    kernel32 = ctypes.WinDLL('kernel32', use_last_error=True)<br>
<br>
    ULONG_PTR = wintypes.WPARAM<br>
<br>
    class OVERLAPPED(ctypes.Structure):<br>
        class _OFF_PTR(ctypes.Union):<br>
            class _OFFSET(ctypes.Structure):<br>
                _fields_ = (('Offset',     wintypes.DWORD),<br>
                            ('OffsetHigh', wintypes.DWORD))<br>
            _fields_ = (('_offset', _OFFSET),<br>
                        ('Pointer', wintypes.LPVOID))<br>
            _anonymous_ = ('_offset',)<br>
        _fields_ = (('Internal',     ULONG_PTR),<br>
                    ('InternalHigh', ULONG_PTR),<br>
                    ('_off_ptr',     _OFF_PTR),<br>
                    ('hEvent',       wintypes.HANDLE))<br>
        _anonymous_ = ('_off_ptr',)<br>
<br>
    with open('test.txt', 'wb') as f:<br>
        f.write(b'0123456789')<br>
<br>
    h = _winapi.CreateFile('test.txt', 0x80000000, 3, 0, 3, 0, 0)<br>
    buf = (ctypes.c_char * 5)()<br>
    n = (wintypes.DWORD * 1)()<br>
    fp = (wintypes.LARGE_INTEGER * 1)()<br>
<br>
    ov = (OVERLAPPED * 1)()<br>
    ov[0].Offset = 5<br>
<br>
<br>
    >>> kernel32.ReadFile(h, buf, 5, n, ov)<br>
    1<br>
    >>> buf[:]<br>
    b'56789'<br>
    >>> kernel32.SetFilePointerEx(h, 0, fp, 1)<br>
    1<br>
    >>> fp[0]<br>
    10<br>
<br>
Note that after reading 5 bytes at an offset of 5, the current file<br>
position is 10. With pread() it would still be at 0. The file position<br>
can be tracked and set atomically before each read or write, but I<br>
don't think this is practical unless it's part of a larger project to<br>
use the Windows API directly.<br>
<br>
<br>
------------------------------<br>
<br>
Message: 4<br>
Date: Mon, 1 Aug 2016 21:57:12 -0700<br>
From: Guido van Rossum <<a href="mailto:guido@python.org">guido@python.org</a>><br>
To: "Steven D'Aprano" <<a href="mailto:steve@pearwood.info">steve@pearwood.info</a>><br>
Cc: Python-Ideas <<a href="mailto:python-ideas@python.org">python-ideas@python.org</a>><br>
Subject: Re: [Python-ideas] Trial balloon: adding variable type<br>
        declarations in support of PEP 484<br>
Message-ID:<br>
        <<a href="mailto:CAP7%2BvJJLz2wRPpkrtb8j8v7vTRFqjbw_b4a5pwAv0-5HyKNf4w@mail.gmail.com">CAP7+vJJLz2wRPpkrtb8j8v7vTRFqjbw_b4a5pwAv0-5HyKNf4w@mail.gmail.com</a>><br>
Content-Type: text/plain; charset=UTF-8<br>
<br>
The parentheses really strike me as too much complexity. You should<br>
just split it up into multiple lines, or use a semicolon.<br>
<br>
On Mon, Aug 1, 2016 at 7:57 PM, Steven D'Aprano <<a href="mailto:steve@pearwood.info">steve@pearwood.info</a>> wrote:<br>
> On Tue, Aug 02, 2016 at 07:40:39AM +1000, Chris Angelico wrote:<br>
><br>
>> Additional case, unless it's patently obvious to someone with more 484<br>
>> experience than I: what happens with chained assignment?<br>
>><br>
>> a = b = c = 0<br>
>><br>
>> Does each variable get separately tagged, or does one tag apply to all?<br>
><br>
> (a:int) = (b:Optional[int]) = c = 0<br>
><br>
> `a` is declared to always be an int, `b` declared to be an int or None,<br>
> and `c` is not declared.<br>
><br>
><br>
><br>
> --<br>
> Steve<br>
> _______________________________________________<br>
> Python-ideas mailing list<br>
> <a href="mailto:Python-ideas@python.org">Python-ideas@python.org</a><br>
> <a href="https://mail.python.org/mailman/listinfo/python-ideas" target="_blank" rel="noreferrer">https://mail.python.org/mailman/listinfo/python-ideas</a><br>
> Code of Conduct: <a href="http://python.org/psf/codeofconduct/" target="_blank" rel="noreferrer">http://python.org/psf/codeofconduct/</a><br>
<br>
<br>
<br>
--<br>
--Guido van Rossum (<a href="http://python.org/~guido" target="_blank" rel="noreferrer">python.org/~guido</a>)<br>
<br>
<br>
------------------------------<br>
<br>
Message: 5<br>
Date: Mon, 1 Aug 2016 22:02:33 -0700<br>
From: Guido van Rossum <<a href="mailto:guido@python.org">guido@python.org</a>><br>
To: "Steven D'Aprano" <<a href="mailto:steve@pearwood.info">steve@pearwood.info</a>><br>
Cc: Python-Ideas <<a href="mailto:python-ideas@python.org">python-ideas@python.org</a>><br>
Subject: Re: [Python-ideas] Trial balloon: adding variable type<br>
        declarations in support of PEP 484<br>
Message-ID:<br>
        <<a href="mailto:CAP7%2BvJJHYLwzbnOqrbqD3vboktXG-Rp%2B8n-MYxm8uf_Ge2m_yQ@mail.gmail.com">CAP7+vJJHYLwzbnOqrbqD3vboktXG-Rp+8n-MYxm8uf_Ge2m_yQ@mail.gmail.com</a>><br>
Content-Type: text/plain; charset=UTF-8<br>
<br>
Regarding class variables: in my experience instance variables way<br>
outnumber class variables, except when the latter are used as defaults<br>
for instance variables.<br>
<br>
See e.g. this bit of code from mypy (and many others, actually):<br>
<a href="https://github.com/python/mypy/blob/master/mypy/nodes.py#L154" target="_blank" rel="noreferrer">https://github.com/python/mypy/blob/master/mypy/nodes.py#L154</a>. All of<br>
these declare instance variables. Many of them have no need for a<br>
default in the class, but must give one anyway or else there's nothing<br>
to put the type comment on -- you can't write<br>
<br>
    defs  # type: List[Statement]<br>
<br>
(it would be a NameError) and you certainly don't want to write<br>
<br>
    defs = []  # type: List[Statement]<br>
<br>
(else the gods of shared mutable state will curse you) so you have to<br>
make do with<br>
<br>
    defs = None  # type: List[Statement]<br>
<br>
But this would be totally reasonable as<br>
<br>
    defs: List[Statement]<br>
<br>
under my proposal.<br>
<br>
On Mon, Aug 1, 2016 at 7:55 PM, Steven D'Aprano <<a href="mailto:steve@pearwood.info">steve@pearwood.info</a>> wrote:<br>
> On Mon, Aug 01, 2016 at 02:31:16PM -0700, Guido van Rossum wrote:<br>
>> PEP 484 doesn't change Python's syntax. Therefore it has no good<br>
>> syntax to offer for declaring the type of variables, and instead you<br>
>> have to write e.g.<br>
>><br>
>> a = 0  # type: float<br>
>> b = []  # type: List[int]<br>
>> c = None  # type: Optional[str]<br>
>><br>
>> I'd like to address this in the future, and I think the most elegant<br>
>> syntax would be to let you write these as follows:<br>
>><br>
>> a: float = 0<br>
>> b: List[int] = []<br>
>> c: Optional[str] = None<br>
><br>
><br>
> Those examples look reasonable to me.<br>
><br>
><br>
> [...]<br>
>> Second, when these occur in a class body, they can define either class<br>
>> variables or instance variables. Do we need to be able to specify<br>
>> which?<br>
><br>
> I would think so. Consider the case that you have Class.spam and<br>
> Class().spam which may not be the same type. E.g. the class attribute<br>
> (representing the default value used by all instances) might be a<br>
> mandatory int, while the instance attribute might be Optional[int].<br>
><br>
><br>
>> Third, there's an annoying thing with tuples/commas here. On the one<br>
>> hand, in a function declaration, we may see (a: int = 0, b: str = '').<br>
>> On the other hand, in an assignment, we may see<br>
>><br>
>> a, b = 0, ''<br>
>><br>
>> Suppose we wanted to add types to the latter. Would we write this as<br>
>><br>
>> a, b: int, str = 0, ''<br>
>><br>
>> or as<br>
>><br>
>> a: int, b: str = 0, ''<br>
><br>
> Require parens around the name:hint.<br>
><br>
> (a:int), (b:str) = 0, ''<br>
><br>
> Or just stick to a type hinting comment :-)<br>
><br>
><br>
> What about this case?<br>
><br>
> spam, eggs = [1, 2.0, 'foo'], (1, '')<br>
> [a, b, c], [d, e] = spam, eggs<br>
><br>
> That becomes:<br>
><br>
> [(a:int), (b:float), (c:str)], [(x:int), (y:str)] = spam, eggs<br>
><br>
> which is bearable, but just unpleasant enough to discourage people from<br>
> doing it unless they really need to.<br>
><br>
><br>
> --<br>
> Steve<br>
> _______________________________________________<br>
> Python-ideas mailing list<br>
> <a href="mailto:Python-ideas@python.org">Python-ideas@python.org</a><br>
> <a href="https://mail.python.org/mailman/listinfo/python-ideas" target="_blank" rel="noreferrer">https://mail.python.org/mailman/listinfo/python-ideas</a><br>
> Code of Conduct: <a href="http://python.org/psf/codeofconduct/" target="_blank" rel="noreferrer">http://python.org/psf/codeofconduct/</a><br>
<br>
<br>
<br>
--<br>
--Guido van Rossum (<a href="http://python.org/~guido" target="_blank" rel="noreferrer">python.org/~guido</a>)<br>
<br>
<br>
------------------------------<br>
<br>
Subject: Digest Footer<br>
<br>
_______________________________________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org">Python-ideas@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-ideas" target="_blank" rel="noreferrer">https://mail.python.org/mailman/listinfo/python-ideas</a><br>
<br>
<br>
------------------------------<br>
<br>
End of Python-ideas Digest, Vol 117, Issue 13<br>
*********************************************<br>
</blockquote></div><br></div>