Skip to content

Commit

Permalink
Change max line size to 88 (#55)
Browse files Browse the repository at this point in the history
* Change max line size to 88

* Line length fixes
  • Loading branch information
dbrattli authored Feb 7, 2022
1 parent 93d5696 commit db7cbd3
Show file tree
Hide file tree
Showing 33 changed files with 559 additions and 180 deletions.
2 changes: 1 addition & 1 deletion .flake8
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[flake8]
ignore = E731, T484, T400 # Do not assign a lambda expression, use a def
max-line-length = 121
max-line-length = 120
32 changes: 27 additions & 5 deletions expression/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,11 @@ def run_command(commands, args, cwd=None, verbose=False, hide_stderr=False, env=
dispcmd = str([c] + args)
# remember shell=False, so use git.cmd on windows, not just git
p = subprocess.Popen(
[c] + args, cwd=cwd, env=env, stdout=subprocess.PIPE, stderr=(subprocess.PIPE if hide_stderr else None)
[c] + args,
cwd=cwd,
env=env,
stdout=subprocess.PIPE,
stderr=(subprocess.PIPE if hide_stderr else None),
)
break
except EnvironmentError:
Expand Down Expand Up @@ -127,7 +131,10 @@ def versions_from_parentdir(parentdir_prefix, root, verbose):
root = os.path.dirname(root) # up a level

if verbose:
print("Tried directories %s but none started with prefix %s" % (str(rootdirs), parentdir_prefix))
print(
"Tried directories %s but none started with prefix %s"
% (str(rootdirs), parentdir_prefix)
)
raise NotThisMethod("rootdir doesn't start with parentdir_prefix")


Expand Down Expand Up @@ -243,7 +250,17 @@ def git_pieces_from_vcs(tag_prefix, root, verbose, run_command=run_command):
# if there is a tag matching tag_prefix, this yields TAG-NUM-gHEX[-dirty]
# if there isn't one, this yields HEX[-dirty] (no NUM)
describe_out, rc = run_command(
GITS, ["describe", "--tags", "--dirty", "--always", "--long", "--match", "%s*" % tag_prefix], cwd=root
GITS,
[
"describe",
"--tags",
"--dirty",
"--always",
"--long",
"--match",
"%s*" % tag_prefix,
],
cwd=root,
)
# --long was added in git-1.5.5
if describe_out is None:
Expand Down Expand Up @@ -285,7 +302,10 @@ def git_pieces_from_vcs(tag_prefix, root, verbose, run_command=run_command):
if verbose:
fmt = "tag '%s' doesn't start with prefix '%s'"
print(fmt % (full_tag, tag_prefix))
pieces["error"] = "tag '%s' doesn't start with prefix '%s'" % (full_tag, tag_prefix)
pieces["error"] = "tag '%s' doesn't start with prefix '%s'" % (
full_tag,
tag_prefix,
)
return pieces
pieces["closest-tag"] = full_tag[len(tag_prefix) :]

Expand All @@ -302,7 +322,9 @@ def git_pieces_from_vcs(tag_prefix, root, verbose, run_command=run_command):
pieces["distance"] = int(count_out) # total number of commits

# commit date: see ISO-8601 comment in git_versions_from_keywords()
date = run_command(GITS, ["show", "-s", "--format=%ci", "HEAD"], cwd=root)[0].strip()
date = run_command(GITS, ["show", "-s", "--format=%ci", "HEAD"], cwd=root)[
0
].strip()
pieces["date"] = date.strip().replace(" ", "T", 1).replace(" ", "", 1)

return pieces
Expand Down
22 changes: 18 additions & 4 deletions expression/collections/asyncseq.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
import builtins
import itertools
from typing import Any, AsyncIterable, AsyncIterator, Callable, Optional, TypeVar, overload
from typing import (
Any,
AsyncIterable,
AsyncIterator,
Callable,
Optional,
TypeVar,
overload,
)

from expression.core import pipe

Expand Down Expand Up @@ -42,7 +50,9 @@ def __aiter__(self) -> AsyncIterator[TSource]:
return self._ai.__aiter__()


def append(other: AsyncIterable[TSource]) -> Callable[[AsyncIterable[TSource]], AsyncIterable[TSource]]:
def append(
other: AsyncIterable[TSource],
) -> Callable[[AsyncIterable[TSource]], AsyncIterable[TSource]]:
async def _append(source: AsyncIterable[TSource]) -> AsyncIterable[TSource]:
async for value in source:
yield value
Expand Down Expand Up @@ -82,7 +92,9 @@ async def range(*args: int, **kw: int) -> AsyncIterable[int]:
yield value


def filter(predicate: Callable[[TSource], bool]) -> Callable[[AsyncIterable[TSource]], AsyncIterable[TSource]]:
def filter(
predicate: Callable[[TSource], bool]
) -> Callable[[AsyncIterable[TSource]], AsyncIterable[TSource]]:
async def _filter(source: AsyncIterable[TSource]) -> AsyncIterable[TSource]:
async for value in source:
if predicate(value):
Expand All @@ -91,7 +103,9 @@ async def _filter(source: AsyncIterable[TSource]) -> AsyncIterable[TSource]:
return _filter


def map(mapper: Callable[[TSource], TResult]) -> Callable[[AsyncIterable[TSource]], AsyncIterable[TResult]]:
def map(
mapper: Callable[[TSource], TResult]
) -> Callable[[AsyncIterable[TSource]], AsyncIterable[TResult]]:
async def _map(source: AsyncIterable[TSource]) -> AsyncIterable[TResult]:
async for value in source:
yield mapper(value)
Expand Down
77 changes: 58 additions & 19 deletions expression/collections/frozenlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,17 @@ def pipe(self, __fn1: Callable[[FrozenList[TSource]], TResult]) -> TResult:
...

@overload
def pipe(self, __fn1: Callable[[FrozenList[TSource]], T1], __fn2: Callable[[T1], T2]) -> T2:
def pipe(
self, __fn1: Callable[[FrozenList[TSource]], T1], __fn2: Callable[[T1], T2]
) -> T2:
...

@overload
def pipe(
self, __fn1: Callable[[FrozenList[TSource]], T1], __fn2: Callable[[T1], T2], __fn3: Callable[[T2], T3]
self,
__fn1: Callable[[FrozenList[TSource]], T1],
__fn2: Callable[[T1], T2],
__fn3: Callable[[T2], T3],
) -> T3:
...

Expand Down Expand Up @@ -139,7 +144,9 @@ def append(self, other: FrozenList[TSource]) -> FrozenList[TSource]:

return FrozenList(self.value + other.value)

def choose(self, chooser: Callable[[TSource], Option[TResult]]) -> FrozenList[TResult]:
def choose(
self, chooser: Callable[[TSource], Option[TResult]]
) -> FrozenList[TResult]:
"""Choose items from the list.
Applies the given function to each element of the list. Returns
Expand All @@ -159,7 +166,9 @@ def mapper(x: TSource) -> FrozenList[TResult]:

return self.collect(mapper)

def collect(self, mapping: Callable[[TSource], FrozenList[TResult]]) -> FrozenList[TResult]:
def collect(
self, mapping: Callable[[TSource], FrozenList[TResult]]
) -> FrozenList[TResult]:
mapped = builtins.map(mapping, self.value)
xs = (y for x in mapped for y in x)
return FrozenList(xs)
Expand Down Expand Up @@ -190,7 +199,9 @@ def filter(self, predicate: Callable[[TSource], bool]) -> FrozenList[TSource]:
"""
return FrozenList(builtins.filter(predicate, self.value))

def fold(self, folder: Callable[[TState, TSource], TState], state: TState) -> TState:
def fold(
self, folder: Callable[[TState, TSource], TState], state: TState
) -> TState:
"""Applies a function to each element of the collection,
threading an accumulator argument through the computation. Take
the second argument, and apply the function to it and the first
Expand Down Expand Up @@ -358,7 +369,9 @@ def tail(self) -> FrozenList[TSource]:
_, *tail = self.value
return FrozenList(tail)

def sort(self: FrozenList[TSourceSortable], reverse: bool = False) -> FrozenList[TSourceSortable]:
def sort(
self: FrozenList[TSourceSortable], reverse: bool = False
) -> FrozenList[TSourceSortable]:
"""Sort list directly.
Returns a new sorted collection.
Expand All @@ -371,7 +384,9 @@ def sort(self: FrozenList[TSourceSortable], reverse: bool = False) -> FrozenList
"""
return FrozenList(builtins.sorted(self.value, reverse=reverse))

def sort_with(self, func: Callable[[TSource], Any], reverse: bool = False) -> FrozenList[TSource]:
def sort_with(
self, func: Callable[[TSource], Any], reverse: bool = False
) -> FrozenList[TSource]:
"""Sort list with supplied function.
Returns a new sorted collection.
Expand Down Expand Up @@ -419,7 +434,9 @@ def try_head(self) -> Option[TSource]:
return Nothing

@staticmethod
def unfold(generator: Callable[[TState], Option[Tuple[TSource, TState]]], state: TState) -> FrozenList[TSource]:
def unfold(
generator: Callable[[TState], Option[Tuple[TSource, TState]]], state: TState
) -> FrozenList[TSource]:
"""Returns a list that contains the elements generated by the
given computation. The given initial state argument is passed to
the element generator.
Expand Down Expand Up @@ -492,21 +509,27 @@ def __repr__(self) -> str:
return str(self)


def append(source: FrozenList[TSource]) -> Callable[[FrozenList[TSource]], FrozenList[TSource]]:
def append(
source: FrozenList[TSource],
) -> Callable[[FrozenList[TSource]], FrozenList[TSource]]:
def _append(other: FrozenList[TSource]) -> FrozenList[TSource]:
return source.append(other)

return _append


def choose(chooser: Callable[[TSource], Option[TResult]]) -> Callable[[FrozenList[TSource]], FrozenList[TResult]]:
def choose(
chooser: Callable[[TSource], Option[TResult]]
) -> Callable[[FrozenList[TSource]], FrozenList[TResult]]:
def _choose(source: FrozenList[TSource]) -> FrozenList[TResult]:
return source.choose(chooser)

return _choose


def collect(mapping: Callable[[TSource], FrozenList[TResult]]) -> Callable[[FrozenList[TSource]], FrozenList[TResult]]:
def collect(
mapping: Callable[[TSource], FrozenList[TResult]]
) -> Callable[[FrozenList[TSource]], FrozenList[TResult]]:
"""For each element of the list, applies the given function.
Concatenates all the results and return the combined list.
Expand Down Expand Up @@ -552,7 +575,9 @@ def cons(head: TSource, tail: FrozenList[TSource]) -> FrozenList[TSource]:
"""The empty list."""


def filter(predicate: Callable[[TSource], bool]) -> Callable[[FrozenList[TSource]], FrozenList[TSource]]:
def filter(
predicate: Callable[[TSource], bool]
) -> Callable[[FrozenList[TSource]], FrozenList[TSource]]:
"""Returns a new collection containing only the elements of the
collection for which the given predicate returns `True`
Expand All @@ -579,7 +604,9 @@ def _filter(source: FrozenList[TSource]) -> FrozenList[TSource]:
return _filter


def fold(folder: Callable[[TState, TSource], TState], state: TState) -> Callable[[FrozenList[TSource]], TState]:
def fold(
folder: Callable[[TState, TSource], TState], state: TState
) -> Callable[[FrozenList[TSource]], TState]:
"""Applies a function to each element of the collection, threading
an accumulator argument through the computation. Take the second
argument, and apply the function to it and the first element of the
Expand All @@ -605,7 +632,9 @@ def _fold(source: FrozenList[TSource]) -> TState:
return _fold


def forall(predicate: Callable[[TSource], bool]) -> Callable[[FrozenList[TSource]], bool]:
def forall(
predicate: Callable[[TSource], bool]
) -> Callable[[FrozenList[TSource]], bool]:
"""Tests if all elements of the collection satisfy the given
predicate.
Expand Down Expand Up @@ -669,7 +698,9 @@ def is_empty(source: FrozenList[Any]) -> bool:
return source.is_empty()


def map(mapper: Callable[[TSource], TResult]) -> Callable[[FrozenList[TSource]], FrozenList[TResult]]:
def map(
mapper: Callable[[TSource], TResult]
) -> Callable[[FrozenList[TSource]], FrozenList[TResult]]:
"""Map list.
Builds a new collection whose elements are the results of applying
Expand All @@ -688,7 +719,9 @@ def _map(source: FrozenList[TSource]) -> FrozenList[TResult]:
return _map


def mapi(mapper: Callable[[int, TSource], TResult]) -> Callable[[FrozenList[TSource]], FrozenList[TResult]]:
def mapi(
mapper: Callable[[int, TSource], TResult]
) -> Callable[[FrozenList[TSource]], FrozenList[TResult]]:
"""Map list with index.
Builds a new collection whose elements are the results of
Expand Down Expand Up @@ -781,7 +814,9 @@ def _skip_last(source: FrozenList[TSource]) -> FrozenList[TSource]:
return _skip_last


def sort(reverse: bool = False) -> Callable[[FrozenList[TSourceSortable]], FrozenList[TSourceSortable]]:
def sort(
reverse: bool = False,
) -> Callable[[FrozenList[TSourceSortable]], FrozenList[TSourceSortable]]:
"""Returns a new sorted collection
Args:
Expand Down Expand Up @@ -883,7 +918,9 @@ def try_head(source: FrozenList[TSource]) -> Option[TSource]:
return source.try_head()


def unfold(generator: Callable[[TState], Option[Tuple[TSource, TState]]]) -> Callable[[TState], FrozenList[TSource]]:
def unfold(
generator: Callable[[TState], Option[Tuple[TSource, TState]]]
) -> Callable[[TState], FrozenList[TSource]]:
"""Returns a list that contains the elements generated by the
given computation. The given initial state argument is passed to
the element generator.
Expand All @@ -905,7 +942,9 @@ def _unfold(state: TState) -> FrozenList[TSource]:
return _unfold


def zip(other: FrozenList[TResult]) -> Callable[[FrozenList[TSource]], FrozenList[Tuple[TSource, TResult]]]:
def zip(
other: FrozenList[TResult],
) -> Callable[[FrozenList[TSource]], FrozenList[Tuple[TSource, TResult]]]:
"""Combines the two lists into a list of pairs. The two lists
must have equal lengths.
Expand Down
Loading

0 comments on commit db7cbd3

Please sign in to comment.