-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Fix class/def line reporting and ignoring for 3.8+. #6753
Conversation
Bump. Hopefully this doesn't get too stale from all of the new sprint PRs! |
Alas, it's already stale. Could you merge the conflicts? |
@gvanrossum Merged, tests are passing. |
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 is getting close, but I have a couple of questions, since this looks like it will be fairly invasive...
mypy/fastparse.py
Outdated
# the opposite end of the range to search for "# type: ignore" | ||
# comments in. This reports the correct line in the event of an | ||
# error, but keeps old pre-3.8 "# type: ignore" comments working | ||
# correctly. |
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 comment confused me. The key thing to note here is that we want to point lineno
to the line that has the def
keyword, while we want to point end_lineno
to the line that would have been used for Python 3.7 and before. And we must compute end_lineno
(i.e. the "old start line") using the crufty way given here since the old way of computing it (i.e. n.lineno + len(n.decorator_list)
won't have the same result in 3.8.
Sorry that this is still so confusing. The code is 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.
Are you going to update these comments? I hope so!
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'll try to reword this to be more concise. Maybe something like:
# Set end_lineno to the old pre-3.8 lineno, in order to keep
# existing "# type: ignore" comments working:
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.
Sounds good -- also for the other location!
mypy/fastparse.py
Outdated
# comments in. This reports the correct line in the event of an | ||
# error, but keeps old pre-3.8 "# type: ignore" comments working | ||
# correctly. | ||
lineno = n.lineno |
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.
Do you even need this? It seems this was already set on line 432 above.
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.
Nice catch. I believe that's left over from an earlier iteration of this change.
mypy/fastparse.py
Outdated
# lineno is where the error is reported, and end_lineno defines the | ||
# opposite end of the range to search for "# type: ignore" comments in. | ||
# This reports the correct line in the event of an error, but keeps old | ||
# pre-3.8 "# type: ignore" comments working correctly. |
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.
Similar comment (except I wasn't really confused here, since I had just figured out the previous one :-).
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.
As above:
# Set end_lineno to the old mypy 0.700 lineno, in order to keep
# existing "# type: ignore" comments working:
New changes are passing, ready for another review. |
Thanks! Congratulations on getting this thorny PR in. Excellent work. |
Thanks, that really means a lot coming from you. Always happy to help! |
Fixes #3871. This change fixes a few things concerning class/function definition line numbers.
For users running mypy with Python 3.8+:
# type: ignore
lines. In other words, existing comments will not need to be moved. This is accomplished by defining an ignore "scope" just like we added to expressions with Expression-scoped ignores in Python 3.8. #6648. See the recent discussion at Function line number information is not always correct #3871 for reasoning.For other users:
About 15 tests had to have their error messages / nodes moved down one line, and 4 new regression tests have been added to
check-38.test
.