Skip to content

Commit

Permalink
Fixed unexisting imports
Browse files Browse the repository at this point in the history
  • Loading branch information
syrusakbary committed Jun 22, 2018
1 parent 462772e commit 5a3b775
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 19 deletions.
2 changes: 1 addition & 1 deletion promise/async_.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Based on https://github.com/petkaantonov/bluebird/blob/master/src/promise.js
from collections import deque
from typing import Callable, Optional, Union # flake8: noqa
if False:

This comment has been minimized.

Copy link
@wojcikstefan

wojcikstefan Sep 13, 2018

Just curious – what's the reasoning for hiding imports behind if False?

This comment has been minimized.

Copy link
@syrusakbary

syrusakbary Sep 13, 2018

Author Owner

It makes mypy static typing work while not requiring the typing package (only available in Python 3) for older versions of Python.

This comment has been minimized.

Copy link
@wojcikstefan

wojcikstefan Sep 14, 2018

I see... Thanks for explaining. It's quite unfortunate that the readability of the codebase is negatively affected simply because of the tooling used to write it.

Ideally the codebase would be in py3 and then it would be translated into py2 code when building the package. That's sort of equivalent to using 2to3 in setup.py, except that you'd want "3to2" :)

from .promise import Promise
from typing import Callable, Optional, Union # flake8: noqa


class Async(object):
Expand Down
14 changes: 4 additions & 10 deletions promise/dataloader.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
from collections import Iterable, namedtuple
from functools import partial

from typing import List, Sized # flake8: noqa

from .promise import Promise, async_instance, get_default_scheduler
from typing import Any
from typing import Callable
from typing import Optional
from typing import Tuple
from typing import Union
from typing import Iterator
from typing import Iterable
from typing import Hashable
if False:
from typing import (
List, Sized, Callable, Optional, Tuple, Union, Iterator, Hashable
) # flake8: noqa


def get_chunks(iterable_obj, chunk_size=1):
Expand Down
3 changes: 1 addition & 2 deletions promise/iterate_promise.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# flake8: noqa
from typing import Iterator

if False:
from .promise import Promise
from typing import Iterator


def iterate_promise(promise):
Expand Down
8 changes: 5 additions & 3 deletions promise/promise.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,21 @@
from types import TracebackType

from six import reraise # type: ignore
from typing import (List, Any, Callable, Dict, Iterator, Optional, # flake8: noqa
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 TypeVar, Generic
# from .schedulers.gevent import GeventScheduler
# from .schedulers.asyncio import AsyncioScheduler
# from .schedulers.thread import ThreadScheduler

if False:
from typing import (List, Any, Callable, Dict, Iterator, Optional, # flake8: noqa
Tuple, Union, Generic, Hashable)


default_scheduler = ImmediateScheduler()

Expand Down
4 changes: 2 additions & 2 deletions promise/promise_list.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from functools import partial
from collections import Iterable
from typing import (Any, Optional, Tuple, Union, List,
Type, Collection) # flake8: noqa
if False:
from .promise import Promise
from typing import (Any, Optional, Tuple, Union, List,
Type, Collection) # flake8: noqa


class PromiseList(object):
Expand Down
2 changes: 1 addition & 1 deletion promise/schedulers/immediate.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from threading import Event
from typing import Callable, Any, Optional # flake8: noqa
if False:
from ..promise import Promise
from typing import Callable, Any, Optional # flake8: noqa


class ImmediateScheduler(object):
Expand Down

0 comments on commit 5a3b775

Please sign in to comment.