-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Editing for the tomllib PEP #3
Conversation
Nope, it's from typeshed https://github.com/python/typeshed/blob/6ff9020603eead6682a0a81f4b6095f00f3b216d/stdlib/_typeshed/__init__.pyi#L171 But yeah, I'm not sure if it's ok to use it in a PEP like this? EDIT: Tomli actually uses EDIT 2: We could define from typing import TypeVar, Protocol
_T_co = TypeVar("_T_co", covariant=True)
class SupportsRead(Protocol[_T_co]):
def read(self) -> _T_co: ... we can simplify further by making it non-generic: from typing import Protocol
class SupportsReadBytes(Protocol):
def read(self) -> bytes: ... |
Co-authored-by: Taneli Hukkinen <[email protected]>
pep-9999.rst
Outdated
For example, ``decimal.Decimal`` can be used in cases where precision is important. | ||
|
||
The returned object contains only basic Python objects (``str``, ``int``, ``bool``, ``float``, | ||
``datetime.{datetime,date,time}``, ``list``, ``dict`` with string keys). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you pass a custom parse_float
, this won't necessarily be true... right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is correct!
The stdlib doesn't use type annotations, the hints should be moved to typeshed anyway. In the PEP, TMO the typing is OK as a summary, as long as it's explained in prose. No need to define it as code. The annotation doesn't capture everything anyway: e.g. how end-of-file is signalled. |
Co-authored-by: Petr Viktorin <[email protected]> Co-authored-by: Taneli Hukkinen <[email protected]>
Thank you for the additional edits! This reads much clearer. I think the draft is in a decent state, so I'll open a PR against python/peps soon :-) |
I found an interesting related discourse discussion. Some takes from there: Guido van Rossum:
Paul Ganssle:
Guido van Rossum:
@hauntsaninja you've worked on mypy a lot, right? Do you know if mypy looks in the stdlib or only typeshed? Of course this isn't very relevant if @encukou isn't interested in such an experiment. |
Hmm, I am interested in the experiment, actually! |
Yes, I'm a maintainer of mypy and typeshed. Type checkers currently only look at typeshed and do not look at standard library code. Type annotations in the stdlib are very controversial; I wouldn't recommend touching that subject. I'm -1 on the idea of stdlib type annotations instead of typeshed, at least for now: Pros:
Cons:
That said, and perhaps more relevant here, I'd be totally fine with modules in the standard library using types for their own documentation (without the expectation that type checkers use them). |
Looks like it'll be best to keep that discussion separate from this PEP. |
SupportsRead
type is specific to tomli, right?tomllib.loads
take str but not bytes, then??