-
Notifications
You must be signed in to change notification settings - Fork 70
Fixing node_printers.py issue caused by refactoring #1239
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
Fixing node_printers.py issue caused by refactoring #1239
Conversation
Pull Request Test Coverage Report for Build 18393632544Details
💛 - Coveralls |
python_ta/reporters/node_printers.py
Outdated
yield from render_context(line - 3, line, source_lines) | ||
yield from RENDERERS[error_code](msg, line, col, source_lines[line - 1]) | ||
yield from render_context(line + 1, line + 3, source_lines) | ||
if error_code in {"E301", "E302", "E303", "E304", "E305", "E306"}: |
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.
Define a constant for this set, making sure to give it a meaningful name
CHANGELOG.md
Outdated
|
||
### 🐛 Bug fixes | ||
|
||
- Fixed issue that caused some error messages to not render properly |
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.
let's be more specific here (refer to the pep8-serrors check)
python_ta/reporters/node_printers.py
Outdated
|
||
|
||
def render_pep8_errors_e306(msg, line, col, source_line=None): | ||
def render_pep8_errors_e306(msg, source_lines=None): |
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.
Same comment as E301
python_ta/reporters/node_printers.py
Outdated
|
||
|
||
def render_pep8_errors_e301(msg, line, col, source_line=None): | ||
def render_pep8_errors_e301(msg, source_lines=None): |
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 function doesn't need to use source_lines
. Instead, it just needs to yield both the message (NEW_BLANK_LINE_MESSAGE
) and the passed in source_line
python_ta/reporters/node_printers.py
Outdated
line -= 1 | ||
line = msg.line - 1 | ||
if "found 0" in msg.msg: | ||
yield from render_context(line - 1, line + 1, source_lines) |
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.
Overall, the same number of lines of context (3) should be shown for all error messages. This means you'll need to update the custom renderers that use source_lines
directly, so that they're consistent with generic approach (Lines 158-160).
In general, this code can be simplified to eliminate some +1/-1 adjustments and make the math more straightforward.
Set line = msg.line
(the standard path on Line 156). Write all render_context
calls in terms of line
(not msg.line
, like on Line 429). Eliminate the line -= 1
statement on Line 425 (changing variable values makes code more complex).
python_ta/reporters/node_printers.py
Outdated
line -= 1 | ||
|
||
body = source_line[msg.line - 1] | ||
yield from render_context(line - 1, line + 1, source_lines) |
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.
Write all of the yield statements together
python_ta/reporters/node_printers.py
Outdated
(curr_line, slice(None, None), LineType.ERROR, " " * (indentation + 28)) | ||
for curr_line in range(line + 1, msg.line) | ||
) | ||
yield from render_context(msg.line, msg.line + 2, source_lines) |
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, only yield lines using the line
variable, not msg.line
python_ta/reporters/node_printers.py
Outdated
|
||
|
||
def render_pep8_errors_e304(msg, line, col, source_line=None): | ||
def render_pep8_errors_e304(msg, source_lines=None): |
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 you can just combine this function with E303. The only difference is the presence of indentation
in E303, which is actually good to do for E304 as well.
python_ta/reporters/node_printers.py
Outdated
def render_pep8_errors_e305(msg, source_lines=None): | ||
"""Render a PEP8 expected 2 blank lines after class or function definition message.""" | ||
line -= 1 | ||
line = msg.line - 1 |
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.
Same comments as above
@Zain-Mahmoud oh right I forgot to mention, you'll also need to do a pull from |
…ork into fixing-node-printers
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 work, @Zain-Mahmoud!
Proposed Changes
Fixed issue where some node_printers.py renderers weren't properly displaying the error messages. This error was caused by the recent refactoring of node_printers.py
...
Screenshots of your changes (if applicable)
Type of Change
(Write an
X
or a brief description next to the type or types that best describe your changes.)Checklist
(Complete each of the following items for your pull request. Indicate that you have completed an item by changing the
[ ]
into a[x]
in the raw text, or by clicking on the checkbox in the rendered description on GitHub.)Before opening your pull request:
After opening your pull request:
Questions and Comments
(Include any questions or comments you have regarding your changes.)