Changeset View
Changeset View
Standalone View
Standalone View
python_modules/dagster/dagster/utils/linter.py
Show First 20 Lines • Show All 73 Lines • ▼ Show 20 Lines | class DagsterChecker(BaseChecker): | ||||
and isinstance(node.func.expr, astroid.node_classes.Name) | and isinstance(node.func.expr, astroid.node_classes.Name) | ||||
and node.func.expr.name == "threading" | and node.func.expr.name == "threading" | ||||
and "daemon" in [keyword.arg for keyword in node.keywords] | and "daemon" in [keyword.arg for keyword in node.keywords] | ||||
): | ): | ||||
self.add_message("daemon-thread", node=node) | self.add_message("daemon-thread", node=node) | ||||
return DagsterChecker | return DagsterChecker | ||||
def register_solid_transform(): | |||||
import astroid | |||||
def _is_solid(node): | |||||
if not node.decorators: | |||||
return False | |||||
return ( | |||||
"dagster.core.definitions.decorators.solid.solid" in node.decoratornames() | |||||
or "dagster.core.definitions.decorators.solid._Solid" in node.decoratornames() | |||||
or "dagster.core.definitions.decorators.composite_solid._CompositeSolid" | |||||
in node.decoratornames() | |||||
or "dagster.core.definitions.decorators.composite_solid.composite_solid" | |||||
in node.decoratornames() | |||||
) | |||||
@astroid.inference_tip | |||||
def _modify_return(node, context=None): | |||||
module = astroid.parse( | |||||
f""" | |||||
def {node.name}(*args, **kwargs): | |||||
return unknown() | |||||
""" | |||||
) | |||||
prha: Having a hard time understanding what this is doing... This replaces the body of every solid… | |||||
alangenfeldAuthorUnsubmitted Done Inline Actionsthis goal is to override the *inference* engines understanding of whats happening in the solid body, so it lo longer uses that information to for example give errors about using the output of invoking a solid due to its inference about its return type. I don't believe this blanks out all linting, just the inference result, by means of this decorator @astroid.inference_tip alangenfeld: this goal is to override the *inference* engines understanding of whats happening in the solid… | |||||
mock_function = next(module.igetattr("solid", context=context)) | |||||
return iter([mock_function]) | |||||
# Register a new inference result for solid decorated functions which effectively | |||||
# blanks out the inference by changing the return type to the output of an unknown function | |||||
astroid.MANAGER.register_transform(astroid.FunctionDef, _modify_return, _is_solid) | |||||
def register(linter): | def register(linter): | ||||
checker = define_dagster_checker() | checker = define_dagster_checker() | ||||
linter.register_checker(checker(linter)) | linter.register_checker(checker(linter)) | ||||
register_solid_transform() | |||||
Done Inline Actionsalangenfeld: inspired by https://stackoverflow.com/questions/38087760/pylint-coroutines-decorators-and-type… | |||||
Not Done Inline Actionswill this help our users avoid this problem, or just help us avoid it in our tests? sandyryza: will this help our users avoid this problem, or just help us avoid it in our tests? | |||||
Done Inline Actionsjust us by default, users who are using pylint can import and use this if they want alangenfeld: just us by default, users who are using `pylint` can import and use this if they want |
Having a hard time understanding what this is doing... This replaces the body of every solid with a call to unknown? Does this mean that we don't get any linting inside of a solid body?