Exemplo n.º 1
0
 def check_physical_eol(self, token: processor._Token,
                        prev_physical: str) -> None:
     """Run physical checks if and only if it is at the end of the line."""
     # a newline token ends a single physical line.
     if processor.is_eol_token(token):
         # if the file does not end with a newline, the NEWLINE
         # token is inserted by the parser, but it does not contain
         # the previous physical line in `token[4]`
         if token[4] == "":
             self.run_physical_checks(prev_physical)
         else:
             self.run_physical_checks(token[4])
     elif processor.is_multiline_string(token):
         # Less obviously, a string that contains newlines is a
         # multiline string, either triple-quoted or with internal
         # newlines backslash-escaped. Check every physical line in the
         # string *except* for the last one: its newline is outside of
         # the multiline string, so we consider it a regular physical
         # line, and will check it like any other physical line.
         #
         # Subtleties:
         # - have to wind self.line_number back because initially it
         #   points to the last line of the string, and we want
         #   check_physical() to give accurate feedback
         line_no = token[2][0]
         with self.processor.inside_multiline(line_number=line_no):
             for line in self.processor.split_line(token):
                 self.run_physical_checks(line + "\n")
Exemplo n.º 2
0
 def check_physical_eol(self, token):
     """Run physical checks if and only if it is at the end of the line."""
     if processor.is_eol_token(token):
         # Obviously, a newline token ends a single physical line.
         self.run_physical_checks(token[4])
     elif processor.is_multiline_string(token):
         # Less obviously, a string that contains newlines is a
         # multiline string, either triple-quoted or with internal
         # newlines backslash-escaped. Check every physical line in the
         # string *except* for the last one: its newline is outside of
         # the multiline string, so we consider it a regular physical
         # line, and will check it like any other physical line.
         #
         # Subtleties:
         # - have to wind self.line_number back because initially it
         #   points to the last line of the string, and we want
         #   check_physical() to give accurate feedback
         line_no = token[2][0]
         with self.processor.inside_multiline(line_number=line_no):
             for line in self.processor.split_line(token):
                 self.run_physical_checks(line + '\n')
Exemplo n.º 3
0
 def check_physical_eol(self, token):
     """Run physical checks if and only if it is at the end of the line."""
     if processor.is_eol_token(token):
         # Obviously, a newline token ends a single physical line.
         self.run_physical_checks(token[4])
     elif processor.is_multiline_string(token):
         # Less obviously, a string that contains newlines is a
         # multiline string, either triple-quoted or with internal
         # newlines backslash-escaped. Check every physical line in the
         # string *except* for the last one: its newline is outside of
         # the multiline string, so we consider it a regular physical
         # line, and will check it like any other physical line.
         #
         # Subtleties:
         # - have to wind self.line_number back because initially it
         #   points to the last line of the string, and we want
         #   check_physical() to give accurate feedback
         line_no = token[2][0]
         with self.processor.inside_multiline(line_number=line_no):
             for line in self.processor.split_line(token):
                 self.run_physical_checks(line + '\n')