Skip to content
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

Incorrect error message: TypeError: sequence item 0: expected str instance, FmtStr found #182

Open
merriam opened this issue May 25, 2024 · 0 comments

Comments

@merriam
Copy link

merriam commented May 25, 2024

An error occurs while trying to make the error message. It causes the misleading message "TypeError: sequence item 0: expected str instance, FmtStr found".

This can be fixed by changing this statement (formatstringarray.py, around line 175):

        msg = "You are trying to fit this value {} into the region {}: {}".format(
            fmtstr("".join(value), bg="cyan"),
            fmtstr("").join(grid_value),
            "\n ".join(grid_fsarray[x] for x in range(len(self.rows))),
        )

to make the "\n " a format string:

        msg = "You are trying to fit this value {} into the region {}: {}".format(
            fmtstr("".join(value), bg="cyan"),
            fmtstr("").join(grid_value),
            fmtstr("\n ").join(grid_fsarray[x] for x in range(len(self.rows))),
        )

This allows the error message not to crash, though it still scrolls off the screen.

      ValueError: Error you are trying to replace a region of 11 rows by 15
                      columns for and area of 165 with a value of len 165. The value
                      used to replace the region must equal the area of the region
                      replace.

The error message has some relevance, but still scrolls off the screen and has typos. It would be better to replace that whole section with:

        if area < 60 and val_len < 60:
          msg = "You are trying to fit this value {} into the region {}: {}".format(
              fmtstr("".join(value), bg="cyan"),
              fmtstr("").join(grid_value),
              fmtstr("\n ").join(grid_fsarray[x] for x in range(len(self.rows))),
          )
        else:
          msg = ""
        raise ValueError(
            """{}
            Error you are trying to replace a region of {} rows by {}
            columns and area of {} with a region of {} rows and total 
            area of {}. The value used to replace the region must equal the 
            area of the region replaced.
            """.format(
              msg,
                rowslice.stop - rowslice.start,
                colslice.stop - colslice.start,
                area,
                len(value),
                val_len,
            )
        )

In my example, I am trying to clear a block with spaces but passed rows and columns incorrectly:

    def clear(self, left, right, top, bottom):
        line = ' ' * max(0, right - left)
        block = [line for _ in range(max(0, bottom - top))]
        print(f"clear {left=} {right=} {top=} {bottom=}\n{len(line)=} {len(block)=}")
        sleep(3)
        self.a[left:right, top:bottom] = [line for _ in range(max(0, bottom - top))]

before changes, I get the TypeError. After the immediate fix, I get output of:

    clear left=8 right=19 top=5 bottom=20
    len(line)=11 len(block)=15
    (pause, scroll past bottom)

      ValueError: Error you are trying to replace a region of 11 rows by 15
                      columns for and area of 165 with a value of len 165. The value
                      used to replace the region must equal the area of the region
                      replace.
       You are trying to fit this value 
       (full width cyan lines continue from the text a few lines, but with "into the region" in the middle
         of the lines.  Below the lines is a block with cyan lines).

after the full fix I get:

    ValueError:
                    Error you are trying to replace a region of 11 rows by 15
                    columns and area of 165 with a region of 15 rows and total
                    area of 165. The value used to replace the region must equal the
                    area of the region replaced.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant