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

spurious unused-import with typing.BinaryIO and type comments #3217

Closed
chadrik opened this issue Oct 25, 2019 · 0 comments
Closed

spurious unused-import with typing.BinaryIO and type comments #3217

chadrik opened this issue Oct 25, 2019 · 0 comments

Comments

@chadrik
Copy link

chadrik commented Oct 25, 2019

Steps to reproduce

Create this file:

from typing import BinaryIO
from typing import List

def foo():
    # type: () -> BinaryIO
    pass

def foo():
    # type: () -> List
    pass

Current behavior

pylint pylint_test.py 
************* Module pylint_test
pylint_test.py:1:0: W0611: Unused BinaryIO imported from typing (unused-import)

------------------------------------------------------------------
Your code has been rated at 5.00/10 (previous run: 6.67/10, -1.67)

Expected behavior

There should not be an error because BinaryIO is used.

It's interesting to note that the behavior is correct for List.

Also, the behavior is correct (no errors) using non-comment annotations

from typing import BinaryIO
from typing import List

def foo() -> BinaryIO:
    pass

def foo() -> List:
    pass

pylint --version output

pylint 2.4.3
astroid 2.3.1
Python 3.7.3 (default, Jun 19 2019, 07:40:15) 
[Clang 10.0.0 (clang-1000.11.45.5)]
chadrik added a commit to chadrik/beam that referenced this issue Oct 27, 2019
chadrik added a commit to chadrik/beam that referenced this issue Dec 9, 2019
pabloem pushed a commit to apache/beam that referenced this issue Dec 11, 2019
* Address issues with a few missing modules/objects

* Ignore some objects missing from typeshed

* Ignore an issue regarding asymmetrical property getter/setter

* Ignore unavoidable errors

Many of these (those marked with [misc]) are due to mypy taking issue with:
- the use of invalid type objects (typehints not typing)
- the use of type objects at runtime

* Ignore some conditional imports in tests

* Ignore functions missing from typeshed

* Add tests for Timestamp/Duration comparisons

* Ignore errors about dynamic base classes

This problem will be fixed when the next version of mypy is released

* Ignore some monkey-patching for tests

* Consolidate python build requirements

This resolves a pip conflict that was happening between setupVirtualenv task
and the tox task by ensuring that everything agrees on the same set of versions.

* Ignore a difficult scenario where None is sometimes unsafe

`None` is only safe to pass as the context to Coder.to_runner_api() when we know that the Coder class does not have components, otherwise the context is used to find and convert them.  We could remove the need for special case `ignores` by reorganizing our Coder class hierarchy to add a CompoundCoder base class or mixin.

Right now this is the only place in the code that we need to ignore this problem, so it's not worth tackling now.

* Add a mypy lint job

The test runs but error status is ignored.

* Workaround a bug in pylint

pylint-dev/pylint#3217

* Add type annotations to bulk of python codebase

There are no meaningful runtime changes in this commit.

* Silence errors about overriding methods.

This seems to be fine to do on an instance as long as the types match, but not on a class.

* Address review notes

* Rebase fixup
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