Changeset View
Changeset View
Standalone View
Standalone View
python_modules/dagster/dagster/utils/linter.py
Show All 17 Lines | class DagsterChecker(BaseChecker): | ||||
"Yield in finally without handling GeneratorExit (see {})".format(INFO_LINK), | "Yield in finally without handling GeneratorExit (see {})".format(INFO_LINK), | ||||
"finally-yield", | "finally-yield", | ||||
"Cannot yield in a finally block without handling GeneratorExit (see {})".format( | "Cannot yield in a finally block without handling GeneratorExit (see {})".format( | ||||
INFO_LINK | INFO_LINK | ||||
), | ), | ||||
), | ), | ||||
"W0002": ("print() call", "print-call", "Cannot call print()"), | "W0002": ("print() call", "print-call", "Cannot call print()"), | ||||
"W0003": ( | "W0003": ( | ||||
"setting daemon=True in threading.Thread constructor", | "Setting daemon=True in threading.Thread constructor", | ||||
"daemon-thread", | "daemon-thread", | ||||
"Cannot set daemon=True in threading.Thread constructor (py2 compat)", | "Cannot set daemon=True in threading.Thread constructor (py2 compat)", | ||||
), | ), | ||||
"W0004": ( | |||||
"Use of now() instead of seven.get_current_datetime_in_utc()", | |||||
"datetime-now", | |||||
"Must use timezone-aware dagster.seven.get_current_datetime_in_utc() for timestamps", | |||||
), | |||||
"W0005": ( | |||||
"Use of utcnow() instead of seven.get_current_datetime_in_utc()", | |||||
"datetime-utcnow", | |||||
"Must use timezone-aware dagster.seven.get_current_datetime_in_utc() for timestamps", | |||||
), | |||||
} | } | ||||
options = () | options = () | ||||
def visit_yield(self, node): | def visit_yield(self, node): | ||||
current = node | current = node | ||||
while current: | while current: | ||||
if isinstance(current, (astroid.ClassDef, astroid.FunctionDef)): | if isinstance(current, (astroid.ClassDef, astroid.FunctionDef)): | ||||
break | break | ||||
Show All 18 Lines | class DagsterChecker(BaseChecker): | ||||
# this try block catches and handles GeneratorExit | # this try block catches and handles GeneratorExit | ||||
return | return | ||||
self.add_message("finally-yield", node=node) | self.add_message("finally-yield", node=node) | ||||
current = current.parent | current = current.parent | ||||
def visit_call(self, node): | def visit_call(self, node): | ||||
if ( | if isinstance(node.func, astroid.node_classes.Name) and node.func.name == "print": | ||||
node.callable | |||||
and isinstance(node.func, astroid.node_classes.Name) | |||||
and node.func.name == "print" | |||||
): | |||||
self.add_message("print-call", node=node) | self.add_message("print-call", node=node) | ||||
if ( | if ( | ||||
node.callable | isinstance(node.func, astroid.node_classes.Attribute) | ||||
and isinstance(node.func, astroid.node_classes.Attribute) | |||||
and node.func.attrname == "Thread" | and node.func.attrname == "Thread" | ||||
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) | ||||
if ( | |||||
isinstance(node.func, astroid.node_classes.Attribute) | |||||
and node.func.attrname == "now" | |||||
and isinstance(node.func.expr, astroid.node_classes.Attribute) | |||||
and node.func.expr.attrname == "datetime" | |||||
): | |||||
self.add_message("datetime-now", node=node) | |||||
if ( | |||||
isinstance(node.func, astroid.node_classes.Attribute) | |||||
and node.func.attrname == "utcnow" | |||||
and isinstance(node.func.expr, astroid.node_classes.Attribute) | |||||
and node.func.expr.attrname == "datetime" | |||||
): | |||||
self.add_message("datetime-utcnow", node=node) | |||||
return DagsterChecker | return DagsterChecker | ||||
def register(linter): | def register(linter): | ||||
checker = define_dagster_checker() | checker = define_dagster_checker() | ||||
linter.register_checker(checker(linter)) | linter.register_checker(checker(linter)) |