-
Notifications
You must be signed in to change notification settings - Fork 57
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
feat: add mypy plugin #384
Conversation
eb899cb
to
289286a
Compare
redis_port = luigi.OptionalParameter(default=None, description='Task lock check is deactivated, when None.', significant=False) | ||
redis_timeout = luigi.IntParameter(default=180, description='Redis lock will be released after `redis_timeout` seconds', significant=False) | ||
redis_host: Optional[str] = luigi.OptionalParameter(default=None, description='Task lock check is deactivated, when None.', significant=False) | ||
redis_port: Optional[int] = luigi.OptionalIntParameter( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
redis_port should be int
@@ -81,7 +81,8 @@ def _test_run_with_empty_data_frame(cmdline_args: List[str], test_run_params: te | |||
|
|||
def try_to_run_test_for_empty_data_frame(cmdline_args: List[str]): | |||
with CmdlineParser.global_instance(cmdline_args): | |||
test_run_params = test_run() | |||
# NOTE: parameters passed by command line cannot be linted by mypy. | |||
test_run_params = test_run() # type: ignore |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mypy-plugin cannot pass this case even though the parameters passed from cmdlin_args
2b8ca03
to
40eed14
Compare
In order to mypy lint effectively
40eed14
to
f5bf4e4
Compare
@@ -0,0 +1,369 @@ | |||
"""Plugin that provides support for gokart.TaskOnKart. | |||
|
|||
This Code reuses the code from mypy.plugins.dataclasses |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code quotes from mypy.plugins.dataclasses
if 'gokart.task.luigi.Task' in fullname: | ||
# gather attibutes from gokart.TaskOnKart | ||
# the transformation does not affect because the class has `__init__` method | ||
return self._task_on_kart_class_maker_callback |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an entrypoint to transform a class to have a __init__
method with luigi. Parameter
s while type-checking for gokart.TaskOnKart
class
|
||
sym = self.lookup_fully_qualified(fullname) | ||
if sym and isinstance(sym.node, TypeInfo): | ||
if any(base.fullname == 'gokart.task.TaskOnKart' for base in sym.node.mro): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is also an entrypoint for inheritance of gokart.TaskOnKart
# then the object default __init__ with an empty signature will be present anyway. | ||
if ('__init__' not in info.names or info.names['__init__'].plugin_generated) and attributes: | ||
args = [attr.to_argument(info, of='__init__') for attr in attributes] | ||
add_method_to_class(self._api, self._cls, '__init__', args=args, return_type=NoneType()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a point which create a method __init__
to a class while type checking
test/test_mypy.py
Outdated
test_file.write(test_code.encode('utf-8')) | ||
test_file.flush() | ||
result = api.run(['--config-file', str(PYPROJECT_TOML), test_file.name]) | ||
self.assertIn('error: Missing named argument "bar" for "MyTask" [call-arg]', result[0]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are error messages for invalid arguments
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GREAT PR! Thanks!
@@ -64,6 +64,7 @@ quote-style = "single" | |||
|
|||
[tool.mypy] | |||
ignore_missing_imports = true | |||
plugins = ["gokart.mypy:plugin"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 👍 👍 👍 👍 👍
👍 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great PR 👍 I will review it thoroughly today.
ded0be5
to
ec0013c
Compare
ec0013c
to
08e2b74
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
What
gokart.TaskOnKart