Skip to content

Add additional flags to mypy config and update type: ignore's #1248

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

Merged
merged 4 commits into from
Nov 17, 2021

Conversation

DanielNoord
Copy link
Collaborator

@DanielNoord DanielNoord commented Nov 17, 2021

Steps

  • For new features or bug fixes, add a ChangeLog entry describing what your PR does.
  • Write a good description on what the PR does.

Description

@cdce8p I think these are the flags we can turn on right now without much trouble.

I also added an error code to every single type: ignore currently in the code.
I couldn't find anything about it online, but do you know if there is a way to require error codes in these ignore messages?

Type of Changes

Type
🔨 Refactoring

Related Issue

Copy link
Member

@Pierre-Sassoulas Pierre-Sassoulas left a comment

Choose a reason for hiding this comment

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

Smell like progress !

no_implicit_optional = True
warn_redundant_casts = True
warn_unused_ignores = True
show_error_codes = True
Copy link
Member

Choose a reason for hiding this comment

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

🎉

@Pierre-Sassoulas
Copy link
Member

I couldn't find anything about it online, but do you know if there is a way to require error codes in these ignore messages?

I think it's --show-error-codes, but we need mypy 9.10 at least.

@DanielNoord
Copy link
Collaborator Author

I don't think that requires you to specify the error you're ignoring in a type: ignore it only shows the error code in the output in the terminal.

@Pierre-Sassoulas
Copy link
Member

Ho, sorry I misunderstood your question. I think this is not yet in mypy : python/mypy#11509

match_mapping: nodes.MatchMapping = assign_stmts.pattern # type: ignore
match_mapping: nodes.MatchMapping = assign_stmts.pattern
Copy link
Member

Choose a reason for hiding this comment

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

The type: ignores here are only unused since the method isn't annotated and thus not type checked.

setup.cfg Outdated
@@ -65,6 +65,10 @@ skip_glob = tests/testdata

[mypy]
scripts_are_modules = True
no_implicit_optional = True
warn_redundant_casts = True
warn_unused_ignores = True
Copy link
Member

Choose a reason for hiding this comment

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

I would remove warn_unused_ignores = True just for now. It isn't an issue at the moment. Instead it's more likely to cause false positives (see comment above). Other false-positives are the two type: ignores in rebuilder.py. They are only necessary in Python 3.9+, thus when checked with 3.8 they are marked as unnecessary.

Copy link
Member

Choose a reason for hiding this comment

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

Look like mypy has the same problem than us for useless-suppression. We could mimic how they handle it ?

Copy link
Member

Choose a reason for hiding this comment

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

Look like mypy has the same problem than us for useless-suppression. We could mimic how they handle it ?

We already do ;) They don't handle it.

Copy link
Member

Choose a reason for hiding this comment

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

I mean they have an option to activate it or not with warn_unused_ignores = True, like we do when we enable useless-suppression, but do you know how they handle discrepancies that appear between python interpreter when unused ignores are activated ?

Copy link
Member

Choose a reason for hiding this comment

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

If the code is evaluated, they emit an error. I.e. not if it's guarded behind a if sys.version_info check what is quite common when using typing.

Co-authored-by: Marc Mueller <30130371+cdce8p@users.noreply.github.com>
@DanielNoord DanielNoord merged commit 5845f21 into pylint-dev:main Nov 17, 2021
@DanielNoord DanielNoord deleted the mypy-flags branch November 17, 2021 11:56
@DanielNoord DanielNoord added this to the 2.8.6 milestone Nov 17, 2021
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

Successfully merging this pull request may close these issues.

3 participants