Running `mypy` on some plugin code I'm seeing a pu...
# plugins
b
Running
mypy
on some plugin code I'm seeing a puzzling error:
Copy code
pants-plugins/mypy_is_a_linter/register.py:4: error: Module                                                                                                                 
'pants.backend.python.typecheck.mypy' has no attribute 'skip_field'
    from pants.backend.python.typecheck.mypy import skip_field, subsystem
    ^
pants-plugins/mypy_is_a_linter/register.py:13: error: Module
'pants.backend.python.util_rules' has no attribute 'pex_from_targets'
    from pants.backend.python.util_rules import pex_from_targets
Running
./pants --no-process-cleanup lint pants-plugins/mypy_is_a_linter/register.py
I can crack open the
pantsbuild
.whl
and see the file there
1
h
wait yeah what
😆 1
idk why it has been so hard to get type hints working w/ pants plugins
b
I have maybe 6 different plugins. This is the only one complaining. And it's only these imports
h
b
FWIW here's the imports for that file. I guess the others are OK, but why?
Copy code
from pants.backend.python.typecheck.mypy import skip_field, subsystem
from pants.backend.python.typecheck.mypy.rules import (
    MyPyPartition,
    MyPyPartitions,
    MyPyRequest,
    mypy_determine_partitions,
    mypy_typecheck_partition,
)
from pants.backend.python.typecheck.mypy.subsystem import MyPy
from pants.backend.python.util_rules import pex_from_targets
from pants.core.goals.check import CheckResult
from pants.core.goals.lint import LintResults, LintTargetsRequest
from pants.engine.rules import Get, MultiGet, collect_rules, rule
from pants.engine.unions import UnionRule
from pants.util.logging import LogLevel
Datapoint: Importing the rules from the file works.
So switching to using
from pants.backend.python.typecheck.mypy.skip_field import rules as skip_rules
works
👎 1
So because I have a workaround, but wtf
h
are we doing something wrong with packages? very confusing topic
b
Adding an
__init__.py
file to the
pants
package root fixes this
h
hm but then i think it breaks testutil package
b
🙈
h
Probably worth filing an issue so that we can track this problem
1
b
What's really curious is that it doesn't error for
subsystem
. another file in the same dir
👀 1
Less curious, the reason it doesn't complain about
subsytem
is the import from
subsystem
below. Removing that makes this reproduce on
subsystem
.