Skip to content

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

Merged
DanielNoord merged 4 commits intopylint-dev:mainfrom
DanielNoord:mypy-flags
Nov 17, 2021
Merged

Add additional flags to mypy config and update type: ignore's#1248
DanielNoord merged 4 commits intopylint-dev:mainfrom
DanielNoord:mypy-flags

Conversation

@DanielNoord
Copy link
Copy Markdown
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
Copy Markdown
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 !

Comment thread setup.cfg
no_implicit_optional = True
warn_redundant_casts = True
warn_unused_ignores = True
show_error_codes = True
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Member

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

Comment thread tests/unittest_protocols.py Outdated
"""
)
match_mapping: nodes.MatchMapping = assign_stmts.pattern # type: ignore
match_mapping: nodes.MatchMapping = assign_stmts.pattern
Copy link
Copy Markdown
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.

Comment thread setup.cfg Outdated
scripts_are_modules = True
no_implicit_optional = True
warn_redundant_casts = True
warn_unused_ignores = True
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

Comment thread tests/unittest_protocols.py Outdated
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