Skip to content

Commit

Permalink
Merge pull request #73 from Shopify/fix-type-errors
Browse files Browse the repository at this point in the history
Fix CI errors on master
  • Loading branch information
sebmartin committed Apr 11, 2019
2 parents 546fcd0 + ed27975 commit e33a323
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 26 deletions.
2 changes: 1 addition & 1 deletion pyoozie/model.py
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
88 changes: 65 additions & 23 deletions pyoozie/tags.py
@@ -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 @@ -496,23 +496,23 @@ def _xml(self, doc, tag, text):
return doc


class _AbstractWorkflowEntity(typing.Iterable):
class _AbstractWorkflowEntity(collections.Iterable):
"""An abstract object representing an Oozie workflow action that can be serialized to XML."""
# pylint: disable=abstract-method

__metaclass__ = abc.ABCMeta

def __init__(
self,
xml_tag=None, # type: typing.Optional[typing.Text]
xml_tag, # type: typing.Text
name=None, # type: typing.Optional[typing.Text]
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 @@ -671,14 +701,20 @@ class Serial(_AbstractWorkflowEntity):

def __init__(self, *entities, **kwargs):
# type: (*_AbstractWorkflowEntity, **_AbstractWorkflowEntity) -> None
super(Serial, self).__init__(on_error=kwargs.get(str('on_error')))
super(Serial, self).__init__(xml_tag='unknown', on_error=kwargs.get(str('on_error')))
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()

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
7 changes: 5 additions & 2 deletions setup.py
Expand Up @@ -46,15 +46,18 @@ def get_version():
'mock',
'pycodestyle == 2.2.0',
'pylint>=1.7.1,<1.8',
'pytest-cov',
'pytest-cov>=2.4.0,<2.6', # pinned, see https://github.com/z4r/python-coveralls/issues/66
'pytest-randomly',
'pytest>=3.0',
'requests-mock',
'shopify_python==0.4.1',
'xmltodict',
'pywebhdfs>=0.4.1',
],
'test: python_version >= "3.3"': [
'test: python_version ~= "3.4"': [ # mypy 0.700 dropped python 3.4 support
'mypy == 0.670',
],
'test: python_version >= "3.5"': [
'mypy',
],
'docs': [
Expand Down

0 comments on commit e33a323

Please sign in to comment.