Skip to content

Commit

Permalink
Fixing issues
Browse files Browse the repository at this point in the history
  • Loading branch information
syrusakbary committed Jun 22, 2018
1 parent d311062 commit 462772e
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 41 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@ matrix:
script: flake8
- python: '3.5'
script: |
pip install mypy
mypy promise/ --check-untyped-defs --ignore-missing-imports
pip install pyre-check
pyre --source-directory promise check
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ With `mypy`

```sh
pip install mypy
mypy promise
mypy promise --ignore-missing-imports
```

with `pyre`:
Expand Down
25 changes: 9 additions & 16 deletions promise/async_.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
# Based on https://github.com/petkaantonov/bluebird/blob/master/src/promise.js
import collections
from .schedulers.immediate import ImmediateScheduler
from typing import Callable
from collections import deque
from typing import Optional
from typing import Union
from typing import Callable, Optional, Union # flake8: noqa
if False:
from .promise import Promise


class Async(object):

def __init__(self):
def __init__(self, trampoline_enabled=True):
self.is_tick_used = False
self.late_queue = collections.deque() # type: ignore
self.normal_queue = collections.deque() # type: ignore
self.late_queue = deque() # type: ignore
self.normal_queue = deque() # type: ignore
self.have_drained_queues = False
self.trampoline_enabled = True
self.trampoline_enabled = trampoline_enabled

def enable_trampoline(self):
self.trampoline_enabled = True
Expand All @@ -32,7 +28,7 @@ def _async_invoke_later(self, fn, scheduler):
self.queue_tick(scheduler)

def _async_invoke(self, fn, scheduler):
# type: (Callable, ImmediateScheduler) -> None
# type: (Callable, Any) -> None
self.normal_queue.append(fn)
self.queue_tick(scheduler)

Expand All @@ -48,7 +44,7 @@ def invoke_later(self, fn):
scheduler.call_later(0.1, fn)

def invoke(self, fn, scheduler):
# type: (Callable, ImmediateScheduler) -> None
# type: (Callable, Any) -> None
if self.trampoline_enabled:
self._async_invoke(fn, scheduler)
else:
Expand All @@ -66,7 +62,7 @@ def settle_promises(self, promise):
)

def throw_later(self, reason, scheduler):
# type: (Exception, ImmediateScheduler) -> None
# type: (Exception, Any) -> None
def fn():
# type: () -> None
raise reason
Expand Down Expand Up @@ -119,8 +115,6 @@ def wait(self, promise, timeout=None):
# We return if the promise is already
# fulfilled or rejected
return
print("WAIT", promise, promise.scheduler, target)

target.scheduler.wait(target, timeout)

def drain_queues(self):
Expand All @@ -132,9 +126,8 @@ def drain_queues(self):
self.drain_queue(self.late_queue)

def queue_tick(self, scheduler):
# type: (ImmediateScheduler) -> None
# type: (Any) -> None
if not self.is_tick_used:
print("QUEUE TICK")
self.is_tick_used = True
scheduler.call(self.drain_queues)

Expand Down
11 changes: 1 addition & 10 deletions promise/promise.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,14 @@

from six import reraise # type: ignore
from typing import (List, Any, Callable, Dict, Iterator, Optional, # flake8: noqa
Union)
Tuple, Union, TypeVar, Generic, Hashable)

from .async_ import Async
from .compat import (Future, ensure_future, iscoroutine, # type: ignore
iterate_promise) # type: ignore
from .utils import deprecated, integer_types, string_types, text_type, binary_type, warn
from .promise_list import PromiseList
from .schedulers.immediate import ImmediateScheduler
from typing import Any
from typing import Callable
from typing import Optional
from typing import Dict
from typing import List
from typing import Union
from typing import Iterator
from typing import Tuple
from typing import TypeVar, Generic, Hashable
# from .schedulers.gevent import GeventScheduler
# from .schedulers.asyncio import AsyncioScheduler
# from .schedulers.thread import ThreadScheduler
Expand Down
9 changes: 2 additions & 7 deletions promise/promise_list.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
from functools import partial
from collections import Iterable
from typing import Any
from typing import Optional
from typing import Tuple
from typing import Union
from typing import List
from typing import Type
from typing import Collection
from typing import (Any, Optional, Tuple, Union, List,
Type, Collection) # flake8: noqa
if False:
from .promise import Promise

Expand Down
2 changes: 1 addition & 1 deletion promise/pyutils/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,6 @@ def get_git_changeset():
)
timestamp = git_log.communicate()[0]
timestamp = datetime.datetime.utcfromtimestamp(int(timestamp))
except:
except Exception:
return None
return timestamp.strftime('%Y%m%d%H%M%S')
4 changes: 1 addition & 3 deletions promise/schedulers/immediate.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from threading import Event
from typing import Callable
from typing import Any
from typing import Optional
from typing import Callable, Any, Optional # flake8: noqa
if False:
from ..promise import Promise

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,6 @@
'test': tests_require,
},
install_requires=[
'typing', 'six'
'typing>=3.6.4', 'six'
],
tests_require=tests_require, )

0 comments on commit 462772e

Please sign in to comment.