This repository has been archived by the owner on Apr 26, 2024. It is now read-only.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Improve type hints for attrs classes #16276
Improve type hints for attrs classes #16276
Changes from all commits
0bd78b1
a35fa4f
21571d1
0558c1e
b12a786
a611a80
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
I think this agrees with Rich prior to d15d241?
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.
Not sure it matters, but is the yield less efficient?
I'm not 100% sure I understand removing
__iter__
and__next__
.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.
Err, being honest it's because I couldn't work out how to annotate the
__iter__
and__next__
in a way that mypy was happy with. Can dig up the errors if you'd like.I think this is equivalent though:
__await__
is supposed to return an iterator__next__
__iter__
redundant? Might have needed it before theawait
syntax added in Py 3.5?)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.
Oh, I think it wasn't redundant because we were returning ourself, now
__await__
itself is an iterator?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.
This explains why
__next__
was needed before my change. But I assert that__iter__
is redundant these days:AFAICS you used to need
__iter__
so that you couldyield from
, back in the days whenasync
wasn't a keyword (a = yield from b
instead ofa = await b
.) If I try to use my class in an old-style coroutine:But if we define
__iter__
: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.
(Tbh we could probably use
asyncio.Future
instead of writing our own)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.
Alas,
Future
docs say: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.
I couldn't resist trying to simplify this. Needs careful checking though, I find all this confusing.
C.f. a0aef0b