<div dir="ltr"><div>As one of the authors of PEP 484, *I* never thought there was an ambiguity here. The intention was for stub files to conform to the same grammar as regular .py files, but with a different interpretation.</div><div><br></div><div>> "Have the same syntax as regular Python modules" and "are files containing type hints" are at odds with each other.<br></div><div><br></div><div>That depends. *same syntax as regular Python* is normative while *containing type hints* is an informal description of intent.</div><div><br></div><div>I happen to be somewhat familiar with the situation that lead to this question -- pytype has its own parser for stub files that cannot parse all Python constructs. But claiming that PEP 484 is ambiguous feels wrong, and if we really need to clarify it the only way to go is to make "same syntax as regular Python" more clearly normative. Type checkers should of course feel free ignore everything they don't care about.<br></div><div><br></div><div>Regarding the unicode issue, that is indeed unfortunate, and there's a long but inconclusive discussion at <a href="https://github.com/python/typing/issues/208">https://github.com/python/typing/issues/208</a>. (If you want a longer discussion here please start a new subject.)<br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Jul 16, 2018 at 1:02 PM, Adam Cataldo via Python-Dev <span dir="ltr"><<a href="mailto:python-dev@python.org" target="_blank">python-dev@python.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Thanks Brett and Teddy,<br><div><br></div><div>Just so it doesn't get lost in the shuffle as folks dive into details, I'll re-ask my earlier question about stub files. Assuming there is consensus that there is ambiguity to resolve in the current definition, is updating the section on stub files the preferred option? The only alternative I can think of is to pull this out into a separate PEP. I frankly have no opinion on what the best way to capture this is. We're happy to help out either way.</div></div><div class="HOEnZb"><div class="h5"><br><div class="gmail_quote"><div dir="ltr">On Mon, Jul 16, 2018 at 12:48 PM Teddy Sudol <<a href="mailto:tsudol@google.com" target="_blank">tsudol@google.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>Hi, my name is Teddy Sudol. I work with Adam and Rebecca on pytype.</div><div><br></div><div>The explanation of stub files is unclear. The section you linked starts with, "Stub files are files containing type hints that are only for use by the type checker, not at runtime." According to <a href="https://www.python.org/dev/peps/pep-0484/#acceptable-type-hints" target="_blank">https://www.python.org/dev/<wbr>peps/pep-0484/#acceptable-<wbr>type-hints</a>, type hints may be classes, abstract base classes, types defined in the `types` and `typing` modules, type variables, type aliases and None. Further in the section you linked, PEP 484 also states, "Stub files have the same syntax as regular Python modules," and, "no runtime behavior should be expected of stub files."</div><div><br></div><div>"Have the same syntax as regular Python modules" and "are files containing type hints" are at odds with each other. This has led to compatibility issues between Mypy and pytype. For example, `b''` is not a valid type annotation, but until a month ago, `codecs.pyi` in typeshed used exactly that: <a href="https://github.com/python/typeshed/commit/6bbf3d89eb9b6c3fd5b0c0f632b2ad9258cecf15#diff-5f6f48c425bc0c283784cf5277880c0cL95" target="_blank">https://github.com/python/<wbr>typeshed/commit/<wbr>6bbf3d89eb9b6c3fd5b0c0f632b2ad<wbr>9258cecf15#diff-<wbr>5f6f48c425bc0c283784cf5277880c<wbr>0cL95</a>. If statements can be useful for things like version checks, but on the other hand, pyi files aren't supposed to have any runtime behavior. Additionally, codifying the syntax for pyi files would settle questions like whether constants should be typed using "x: <type hint>" or "x = ...  # type: <type hint>".</div><div><br></div><div>We would like to see a clear statement about the syntax of stub files.  Personally, I think they should be a subset of Python, but I'd also be happy with an EBNF grammar for them.</div><div><br></div><div><div dir="ltr" class="m_-1245136029280977671m_-2617861788207076734gmail_signature"><div dir="ltr">-- Teddy</div></div></div><br></div><br><div class="gmail_quote"><div dir="ltr">On Mon, Jul 16, 2018 at 11:05 AM Brett Cannon <<a href="mailto:brett@python.org" target="_blank">brett@python.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><br><br><div class="gmail_quote"><div dir="ltr">On Mon, 16 Jul 2018 at 10:32 Adam Cataldo via Python-Dev <<a href="mailto:python-dev@python.org" target="_blank">python-dev@python.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><b style="font-weight:normal" id="m_-1245136029280977671m_-2617861788207076734m_-6437177495062479949m_8766945090312936540gmail-docs-internal-guid-88ce2fd6-a41a-e9a5-1b4f-290bb5c627fc"><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-family:Arial;color:rgb(0,0,0);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap">Hi Folks,</span></p><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-family:Arial;color:rgb(0,0,0);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap">Cc: Rebecca, pytype</span></p><br><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-family:Arial;color:rgb(0,0,0);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap">This is Adam Cataldo; I’m the engineering manager for the Python team at Google. Rebecca Chen, our lead </span><a href="https://github.com/google/pytype" style="text-decoration:none" target="_blank"><span style="font-family:Arial;color:rgb(17,85,204);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:underline;vertical-align:baseline;white-space:pre-wrap">pytype</span></a><span style="font-family:Arial;color:rgb(0,0,0);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap"> contributor, and I are interested in helping finalize PEP 484 if possible. To that end, we wanted to find out what technical issues the PEP 484 authors feel they still need to finalize. We also wanted to know how we can help.</span></p><br><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-family:Arial;color:rgb(0,0,0);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap">We have a large Python code base at Google, and may be able to use this to help resolve current incomplete definitions, by collecting data on how types are used. We also have a couple ambiguities that we’d love to get closure on:</span></p><br><ul style="margin-top:0pt;margin-bottom:0pt"><li dir="ltr" style="list-style-type:disc;font-family:Arial;color:rgb(0,0,0);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap"><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-family:Arial;color:rgb(0,0,0);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap">One thing we care about in particular, given the implementation of pytype, is the detailed definition of what goes in a .pyi file. Do folks think this makes sense to include as part of PEP 484, or would this be better in a separate PEP? We’d love to get your thoughts.</span></p></li></ul></b></div></blockquote><div><br></div><div>What specifically do you want beyond <a href="https://www.python.org/dev/peps/pep-0484/#stub-files" target="_blank">https://www.python.org/dev/<wbr>peps/pep-0484/#stub-files</a>?<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><b style="font-weight:normal" id="m_-1245136029280977671m_-2617861788207076734m_-6437177495062479949m_8766945090312936540gmail-docs-internal-guid-88ce2fd6-a41a-e9a5-1b4f-290bb5c627fc"><ul style="margin-top:0pt;margin-bottom:0pt"><li dir="ltr" style="list-style-type:disc;font-family:Arial;color:rgb(0,0,0);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap"><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-family:Arial;color:rgb(0,0,0);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap">The relationship between unicode and typing.Text in Python 2 has been a recurring source of confusion for our users. Especially since we </span><a href="https://github.com/python/peps/pull/302" style="text-decoration:none" target="_blank"><span style="font-family:Arial;color:rgb(17,85,204);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:underline;vertical-align:baseline;white-space:pre-wrap">contributed</span></a><span style="font-family:Arial;color:rgb(0,0,0);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap"> to the current state of affairs, we’d like to figure out how to establish clarity here.</span></p></li></ul><br><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-family:Arial;color:rgb(0,0,0);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap">Thoughts?</span></p></b></div></blockquote><div> </div><div>Do be aware, Adam, that due to Guido's retirement last week people might be a bit preoccupied and so a little slow in responding. But then again Guido just got a bit more free time so he might chime in on this one. ;)<br></div></div></div>

<p></p>

-- <br>
You received this message because you are subscribed to the Google Groups "pytype" group.<br>
To unsubscribe from this group and stop receiving emails from it, send an email to <a href="mailto:pytype+unsubscribe@googlegroups.com" target="_blank">pytype+unsubscribe@<wbr>googlegroups.com</a>.<br>
To post to this group, send email to <a href="mailto:pytype@googlegroups.com" target="_blank">pytype@googlegroups.com</a>.<br>
To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/pytype/CAP1%3D2W4NxcsSdsiMrh55KhjkwgD0PGRcZJF_Azq3g6QFQ2oiAw%40mail.gmail.com?utm_medium=email&utm_source=footer" target="_blank">https://groups.google.com/d/<wbr>msgid/pytype/CAP1%<wbr>3D2W4NxcsSdsiMrh55KhjkwgD0PGRc<wbr>ZJF_Azq3g6QFQ2oiAw%40mail.<wbr>gmail.com</a>.<br>
For more options, visit <a href="https://groups.google.com/d/optout" target="_blank">https://groups.google.com/d/<wbr>optout</a>.<br>
</blockquote></div>
</blockquote></div>
</div></div><br>______________________________<wbr>_________________<br>
Python-Dev mailing list<br>
<a href="mailto:Python-Dev@python.org">Python-Dev@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-dev" rel="noreferrer" target="_blank">https://mail.python.org/<wbr>mailman/listinfo/python-dev</a><br>
Unsubscribe: <a href="https://mail.python.org/mailman/options/python-dev/guido%40python.org" rel="noreferrer" target="_blank">https://mail.python.org/<wbr>mailman/options/python-dev/<wbr>guido%40python.org</a><br>
<br></blockquote></div><br><br clear="all"><br>-- <br><div class="gmail_signature" data-smartmail="gmail_signature">--Guido van Rossum (<a href="http://python.org/~guido" target="_blank">python.org/~guido</a>)</div>
</div>