Skip to content

Add "--no-pretty" as default argument to mypy - #17564

Merged
Karthik Nadig (karthiknadig) merged 1 commit into
microsoft:mainfrom
lithammer:mypy-no-pretty
Oct 14, 2021
Merged

Karthik Nadig (karthiknadig) merged 1 commit into
microsoft:mainfrom
lithammer:mypy-no-pretty

Conversation

@lithammer

@lithammer Peter Lithammer (lithammer) commented Sep 29, 2021 •

Copy link
Copy Markdown

This fixes an issue when the error text gets truncated because of project local settings. As you can see from the example below, the output with --pretty is wrapped (at 80 chars?) when piped.

The wrapped lines are truncated from the error message.

$ cat > pyproject.toml <<<EOF
[tool.mypy]
pretty = true
EOF

$ cat > foobar.py <<<
def foobar(a: int):
    pass

foobar("123")
EOF

$ mypy foobar.py
foobar.py:5: error: Argument 1 to "foobar" has incompatible type "str"; expected "int"
    foobar("123")
           ^
Found 1 error in 1 file (checked 1 source file)

$ mypy foobar.py | cat
foobar.py:5: error: Argument 1 to "foobar" has incompatible type "str";
expected "int"
    foobar("123")
           ^
Found 1 error in 1 file (checked 1 source file)

$ mypy --no-pretty foobar.py
foobar.py:5: error: Argument 1 to "foobar" has incompatible type "str"; expected "int"
Found 1 error in 1 file (checked 1 source file)

$ mypy --no-pretty foobar.py | cat
foobar.py:5: error: Argument 1 to "foobar" has incompatible type "str"; expected "int"
Found 1 error in 1 file (checked 1 source file)

Without --no-pretty:

Screenshot 2021-09-29 at 09 45 51

With --no-pretty:

Screenshot 2021-09-29 at 09 46 20

Fixes #16836

Comment thread package.json
"--ignore-missing-imports",
"--show-column-numbers"
"--show-column-numbers",
"--no-pretty"

@lithammer Peter Lithammer (lithammer) Sep 29, 2021 •

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For similar reasons it would probably be nice to add --no-error-summary and maybe --hide-error-context as well.

@karthiknadig

Copy link
Copy Markdown
Member

Peter Lithammer (@lithammer) Thanks for the PR. Can you create a bug for this issue? and add a news item based on that issue number. Create a file <issue-number>.md under news/2 Fixes with content like:

<change log comment for this fix>.
(thanks [Peter Lithammer](https://github.com/lithammer))

For adding --no-error-summary and --hide-error-context, once you create the issue we can discuss if it should be added.

@lithammer

Peter Lithammer (lithammer) commented Oct 5, 2021 •

Copy link
Copy Markdown
Author

Thanks for reviewing. I had a look at existing issues and it would seem that adding --no-pretty would also fix this issue:

Should I create a news item for that as well? Or should I perhaps just re-use that issue instead of creating my own?

@karthiknadig

Copy link
Copy Markdown
Member

Yes you can use #16836 as the news file.

@ghost

Deleted user (ghost) commented Oct 5, 2021 •

Copy link
Copy Markdown

CLA assistant check
All CLA requirements met.

This fixes an issue when the error text gets truncated because of
project local settings. As you can see from the example below, the
output with `--pretty` is wrapped (at 80 chars?) when piped.

The wrapped lines are truncated from the error message.

```console
$ cat > pyproject.toml <<<EOF
[tool.mypy]
pretty = true
EOF

$ cat > foobar.py <<<
def foobar(a: int):
    pass

foobar("123")
EOF

$ mypy foobar.py
foobar.py:5: error: Argument 1 to "foobar" has incompatible type "str"; expected "int"
    foobar("123")
           ^
Found 1 error in 1 file (checked 1 source file)

$ mypy foobar.py | cat
foobar.py:5: error: Argument 1 to "foobar" has incompatible type "str";
expected "int"
    foobar("123")
           ^
Found 1 error in 1 file (checked 1 source file)

$ mypy --no-pretty foobar.py
foobar.py:5: error: Argument 1 to "foobar" has incompatible type "str"; expected "int"
Found 1 error in 1 file (checked 1 source file)

$ mypy --no-pretty foobar.py | cat
foobar.py:5: error: Argument 1 to "foobar" has incompatible type "str"; expected "int"
Found 1 error in 1 file (checked 1 source file)
```
@lithammer

Copy link
Copy Markdown
Author

Yes you can use #16836 as the news file.

Done!

@lithammer

Peter Lithammer (lithammer) commented Oct 6, 2021 •

Copy link
Copy Markdown
Author

Error: "package.json" was edited but "package-lock.json" was not (the "skip package*.json" label can be used to pass this check)

Not sure what the deal is with this failing check... 🤷‍♂️ Tried to rebase, but no bueno.

@karthiknadig Karthik Nadig (karthiknadig) added the skip package*.json package.json and package-lock.json don't both need updating label Oct 6, 2021
@karthiknadig

Copy link
Copy Markdown
Member

That is just a check to ensure we have not missed any package update in package lock. Cleared it with "skip package*.json"

@lithammer

Copy link
Copy Markdown
Author

Anything more you need me to do?

@karthiknadig

Copy link
Copy Markdown
Member

Peter Lithammer (@lithammer) nothing for now. We are doing some repo maintenance, we will merge this soon.

@karthiknadig
Karthik Nadig (karthiknadig) merged commit 3ca8a41 into microsoft:main Oct 14, 2021
@lithammer
Peter Lithammer (lithammer) deleted the mypy-no-pretty branch October 15, 2021 13:53
Wes McKinney (wesm) pushed a commit to posit-dev/positron that referenced this pull request Mar 28, 2024
…python#17564)

This fixes an issue when the error text gets truncated because of
project local settings. As you can see from the example below, the
output with `--pretty` is wrapped (at 80 chars?) when piped.

The wrapped lines are truncated from the error message.

```console
$ cat > pyproject.toml <<<EOF
[tool.mypy]
pretty = true
EOF

$ cat > foobar.py <<<
def foobar(a: int):
    pass

foobar("123")
EOF

$ mypy foobar.py
foobar.py:5: error: Argument 1 to "foobar" has incompatible type "str"; expected "int"
    foobar("123")
           ^
Found 1 error in 1 file (checked 1 source file)

$ mypy foobar.py | cat
foobar.py:5: error: Argument 1 to "foobar" has incompatible type "str";
expected "int"
    foobar("123")
           ^
Found 1 error in 1 file (checked 1 source file)

$ mypy --no-pretty foobar.py
foobar.py:5: error: Argument 1 to "foobar" has incompatible type "str"; expected "int"
Found 1 error in 1 file (checked 1 source file)

$ mypy --no-pretty foobar.py | cat
foobar.py:5: error: Argument 1 to "foobar" has incompatible type "str"; expected "int"
Found 1 error in 1 file (checked 1 source file)
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip package*.json package.json and package-lock.json don't both need updating

Projects

None yet

Development

Successfully merging this pull request may close these issues.

no visual indication of mypy pretty linting errors on path names of >80 chars

2 participants