-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Prevent unused-import
for if t.TYPE_CHECKING
#6787
Prevent unused-import
for if t.TYPE_CHECKING
#6787
Conversation
I had a lot of
|
Pull Request Test Coverage Report for Build 2447711665
π - Coveralls |
@jacobtylerwalls I'll keep my approval, but we're missing coverage for one line. Luckily, I think a test is pretty straightforward! |
This comment has been minimized.
This comment has been minimized.
Thanks, primer! |
This comment has been minimized.
This comment has been minimized.
@DanielNoord that's a lot of false positives fixed in We still have some indeterminacy in I linted a relevant $ python3 -m pylint tests/.pylint_primer_tests/pandas-dev/pandas/pandas/tests/indexes/multi/test_reshape.py
************* Module pandas.tests.indexes.multi.test_reshape
tests/.pylint_primer_tests/pandas-dev/pandas/pandas/tests/indexes/multi/test_reshape.py:126:4: R0204: Redefinition of result type from pandas.core.indexes.base.Index to pandas.core.indexes.multi.MultiIndex (redefined-variable-type)
tests/.pylint_primer_tests/pandas-dev/pandas/pandas/tests/indexes/multi/test_reshape.py:131:4: R0204: Redefinition of expected type from pandas.core.indexes.base.Index to pandas.core.indexes.multi.MultiIndex (redefined-variable-type)
------------------------------------------------------------------
Your code has been rated at 9.80/10 (previous run: 9.80/10, +0.00) |
It seems the output of See the first lines for |
Relevant: pylint-dev/astroid#1107. Maybe these changes should go there. And not backport this but get in astroid2.12/pylint2.15? With the deprecations to get rid of the extra methods. |
Ah I had been looking for that issue in Yeah, this seems like it might fit better upstream. |
I'm looking into the changelog hook error. It's strange that the result is not the same depending on the environment. Could you add the verbose option and give me the result @jacobtylerwalls ? |
>>> content
":Release: 2.1\n:Date: 2018-08-01\n\nSummary -- Release highlights\n=============================\n\n* This release mostly includes fixes for bugs found after the launch of 2.0.\n\nNew checkers\n============\n\n* A new check was added, ``misplaced-format-function``.\n\n This message is emitted when pylint detects that a format function is called on non str object.\n This can occur due to wrong placement of closing bracket, e.g\n\n .. code-block:: python\n\n print('value: {}').format(123) # bad\n\n print('value: {}'.format(123)) # good\n\n\nOther Changes\n=============\n\n* ``try-except-raise`` check was demoted from an error to a warning, as part of issue #2323.\n\n* Correctly handle the new name of the Python implementation of the ``abc`` module.\n\n In Python 3.7, the ``abc`` module has both a C implementation as well as a Python one,\n but the Python implementation has a different file name that what ``pylint`` was expecting,\n resulting in some checks getting confused.\n\n* Modules with ``__getattr__`` are exempted by default from ``no-member``\n\n There's no easy way to figure out if a module has a particular member when\n the said module uses ``__getattr__``, which is a new addition to Python 3.7.\n Instead we assume the safe thing to do, in the same way we do for classes,\n and skip those modules from checking.\n\n\n* ``invalid name`` is no longer triggered for function and attribute names longer\n than 30 characters. The upper limit was removed completely.\n\n\n* Fix false-positive ``undefined-variable`` for self referential class name in lamdbas\n\n* ``no-else-return`` also specifies the type of the branch that is causing the error.\n\n* Fixed inconsistent behaviour for bad-continuation on first line of file.\n\n* Fixed a bug where ``pylint`` was not able to disable certain messages on the last line through\n the global disable option.\n\n* ``pylint`` no longer emits ``useless-return`` when it finds a single statement that is the ``return`` itself\n\n We still want to be explicit when a function is supposed to return\n an optional value; even though ``pass`` could still work, it's not explicit\n enough and the function might look like it's missing an implementation.\n\n* Fixed a bug where ``pylint`` was crashing when being unable to infer the value of an argument to ``next()``\n\n\n* ``pylint`` no longer emit ``not-an-iterable`` when dealing with async iterators.\n\n* ``pylint`` gained the ability to specify a default docstring type for when the check cannot guess the type\n\n For this we added a ``--default-docstring-type`` command line option.\n"
>>> from re import Pattern
>>>
>>> VALID_ISSUES_KEYWORDS = ["Refs", "Closes", "Follow-up in", "Fixes part of"]
>>> ISSUE_NUMBER_PATTERN = r"#\d{1,5}"
>>> VALID_ISSUE_NUMBER_PATTERN = r"\*[\S\s]*?" + ISSUE_NUMBER_PATTERN
>>> ISSUES_KEYWORDS = "|".join(VALID_ISSUES_KEYWORDS)
>>> PREFIX_CHANGELOG_PATTERN = (
... rf"(\*\s[\S[\n ]+?]*\n\n\s\s({ISSUES_KEYWORDS})) (PyCQA/astroid)?"
... )
>>> VALID_CHANGELOG_PATTERN = PREFIX_CHANGELOG_PATTERN + ISSUE_NUMBER_PATTERN
>>>
>>> ISSUE_NUMBER_COMPILED_PATTERN = re.compile(ISSUE_NUMBER_PATTERN)
>>> VALID_CHANGELOG_COMPILED_PATTERN: Pattern[str] = re.compile(VALID_CHANGELOG_PATTERN)
>>> VALID_ISSUE_NUMBER_COMPILED_PATTERN: Pattern[str] = re.compile(
... VALID_ISSUE_NUMBER_PATTERN
... )
>>> VALID_CHANGELOG_COMPILED_PATTERN.findall(content)
[] |
(The only additional output in verbose mode was a bunch of LGTM) |
Ah, nvm -- the util in |
7b601dc
to
b7d14fb
Compare
Type of Changes
Description
The check for
typing.TYPE_CHECKING
was not robust against importingtyping
ast
. Nor against importingkeyboarding
astyping
. This could lead to false positives forunused-import
.Follow-up: we have the following plethora of utils. Would be good to standardize and deprecate some for 2.15 (not a backport task, though):
Closes #3846