Skip to content

Commit

Permalink
fix type errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Seb Martin committed Apr 10, 2019
1 parent 546fcd0 commit f715d6e
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 21 deletions.
2 changes: 1 addition & 1 deletion pyoozie/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ class _OozieArtifact(object):

REQUIRED_KEYS = {} # type: typing.Dict[unicode, typing.Callable]

SUPPORTED_KEYS = {'toString': None} # type: typing.Dict[unicode, typing.Callable]
SUPPORTED_KEYS = {'toString': None} # type: typing.Dict[unicode, typing.Optional[typing.Callable]]

def __init__(self, oozie_client, details, parent=None):
self._client = oozie_client
Expand Down
82 changes: 62 additions & 20 deletions pyoozie/tags.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
# Copyright (c) 2017 "Shopify inc." All rights reserved.
# Use of this source code is governed by a MIT-style license that can be found in the LICENSE file.
from __future__ import unicode_literals

import abc
import collections
import copy
import datetime
import enum
import itertools
import re
import string # pylint: disable=deprecated-module
import uuid

import enum
import typing # pylint: disable=unused-import
import uuid

import six
import yattag
Expand Down Expand Up @@ -509,10 +509,10 @@ def __init__(
on_error=None # type: typing.Optional[_AbstractWorkflowEntity]
):
# type: (...) -> None
self.__xml_tag = xml_tag
self.__xml_tag = xml_tag or 'unknown'
self.__name = name if name else uuid.uuid4().hex[:8]
self.__on_error = copy.deepcopy(on_error)
self.__identifier = self.create_identifier(xml_tag)
self.__identifier = self.create_identifier(self.__xml_tag)

def xml_tag(self):
# type: () -> typing.Text
Expand All @@ -526,17 +526,29 @@ def create_identifier(self, xml_tag):
# type: (typing.Text) -> typing.Text
return validate_xml_id('{tag}-{name}'.format(tag=xml_tag, name=self.__name))

def _xml_and_get_on_error(self, doc, tag, text, on_next, on_error):
# type: (yattag.doc.Doc, yattag.doc.Doc.tag, yattag.doc.Doc.text, typing.Text, typing.Text) -> yattag.doc.Doc
def _xml_and_get_on_error(
self,
doc, # type: yattag.doc.Doc
tag, # type: yattag.doc.Doc.tag
text, # type: yattag.doc.Doc.Text
on_next, # type: typing.Text
on_error # type: typing.Optional[typing.Text]
):
if self.__on_error:
self.__on_error._xml(doc, tag, text, on_next, on_error)
return self.__on_error.identifier() if self.__on_error else (
on_error if on_error else on_next
)

@abc.abstractmethod
def _xml(self, doc, tag, text, on_next, on_error):
# type: (yattag.doc.Doc, yattag.doc.Doc.tag, yattag.doc.Doc.text, typing.Text, typing.Text) -> yattag.doc.Doc
def _xml(
self,
doc, # type: yattag.doc.Doc
tag, # type: yattag.doc.Doc.tag
text, # type: yattag.doc.Doc.Text
on_next, # type: typing.Text
on_error # type: typing.Optional[typing.Text]
):
raise NotImplementedError()

def __iter__(self):
Expand Down Expand Up @@ -564,8 +576,14 @@ def __init__(self, message, name=None):
super(Kill, self).__init__(xml_tag='kill', name=name)
self.message = message

def _xml(self, doc, tag, text, on_next, on_error):
# type: (yattag.doc.Doc, yattag.doc.Doc.tag, yattag.doc.Doc.text, typing.Text, typing.Text) -> yattag.doc.Doc
def _xml(
self,
doc, # type: yattag.doc.Doc
tag, # type: yattag.doc.Doc.tag
text, # type: yattag.doc.Doc.Text
on_next, # type: typing.Text
on_error # type: typing.Optional[typing.Text]
):
with tag(self.xml_tag(), name=self.identifier()):
with tag('message'):
doc.text(self.message)
Expand Down Expand Up @@ -600,8 +618,14 @@ def credential(self):
# type: () -> typing.Optional[typing.Text]
return self.__credential

def _xml(self, doc, tag, text, on_next, on_error):
# type: (yattag.doc.Doc, yattag.doc.Doc.tag, yattag.doc.Doc.text, typing.Text, typing.Text) -> yattag.doc.Doc
def _xml(
self,
doc, # type: yattag.doc.Doc
tag, # type: yattag.doc.Doc.tag
text, # type: yattag.doc.Doc.Text
on_next, # type: typing.Text
on_error # type: typing.Optional[typing.Text]
):
_on_error = self._xml_and_get_on_error(doc, tag, text, on_next, on_error)

attributes = {
Expand Down Expand Up @@ -638,8 +662,14 @@ def __init__(
self.__default = copy.deepcopy(default)
self.__choices = copy.deepcopy(choices)

def _xml(self, doc, tag, text, on_next, on_error):
# type: (yattag.doc.Doc, yattag.doc.Doc.tag, yattag.doc.Doc.text, typing.Text, typing.Text) -> yattag.doc.Doc
def _xml(
self,
doc, # type: yattag.doc.Doc
tag, # type: yattag.doc.Doc.tag
text, # type: yattag.doc.Doc.Text
on_next, # type: typing.Text
on_error # type: typing.Optional[typing.Text]
):
_on_error = self._xml_and_get_on_error(doc, tag, text, on_next, on_error)

# Write switch/case
Expand Down Expand Up @@ -675,10 +705,16 @@ def __init__(self, *entities, **kwargs):
self.__entities = tuple(copy.deepcopy(entities)) # type: typing.Tuple[_AbstractWorkflowEntity, ...]

def identifier(self): # type: () -> typing.Text
return self.__entities[0].identifier() if self.__entities else None
return self.__entities[0].identifier() if self.__entities else ''

def _xml(self, doc, tag, text, on_next, on_error):
# type: (yattag.doc.Doc, yattag.doc.Doc.tag, yattag.doc.Doc.text, typing.Text, typing.Text) -> yattag.doc.Doc
def _xml(
self,
doc, # type: yattag.doc.Doc
tag, # type: yattag.doc.Doc.tag
text, # type: yattag.doc.Doc.Text
on_next, # type: typing.Text
on_error # type: typing.Optional[typing.Text]
):
_on_error = self._xml_and_get_on_error(doc, tag, text, on_next, on_error)
entity_nextidentifier = zip(self.__entities, itertools.chain(
(a.identifier() for a in self.__entities[1:]),
Expand Down Expand Up @@ -714,8 +750,14 @@ def __init__(self, *entities, **kwargs):
assert entities, 'At least 1 entity required'
self.__entities = frozenset(copy.deepcopy(entities)) # type: typing.FrozenSet[_AbstractWorkflowEntity]

def _xml(self, doc, tag, text, on_next, on_error):
# type: (yattag.doc.Doc, yattag.doc.Doc.tag, yattag.doc.Doc.text, typing.Text, typing.Text) -> yattag.doc.Doc
def _xml(
self,
doc, # type: yattag.doc.Doc
tag, # type: yattag.doc.Doc.tag
text, # type: yattag.doc.Doc.Text
on_next, # type: typing.Text
on_error # type: typing.Optional[typing.Text]
):
_on_error = self._xml_and_get_on_error(doc, tag, text, on_next, on_error)
with tag(self.xml_tag(), name=self.identifier()):
for entity in self.__entities:
Expand Down

0 comments on commit f715d6e

Please sign in to comment.