Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider applying black to format the code #110

Closed
wants to merge 2 commits into from
Closed

Conversation

hardbyte
Copy link
Collaborator

@hardbyte hardbyte commented Apr 13, 2018

See #99

This PR is simply the diff after running:

black -l 120 clkhash

This is more for discussion that merging right now. I don't know why I chose a line wrap length of 120 - maybe my wide monitor influenced me...

Copy link
Contributor

@nbgl nbgl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To conform with PEP8, all lines should be limited to 79 characters.

As a matter of personal taste, I prefer using single quotes to double quotes for strings. Is it possible to set Black to single quotes?

Finally, these changes break the type annotation syntax. (https://travis-ci.org/n1analytics/clkhash/jobs/365941315)

@hardbyte
Copy link
Collaborator Author

As a matter of personal taste, I prefer using single quotes to double quotes for strings. Is it possible to set Black to single quotes?

To quote directly from the intro to black:

By using it, you agree to cease control over minutiae of hand-formatting. In return, Black gives you speed, determinism, and freedom from pycodestyle nagging about formatting. You will save time and mental energy for more important matters.

So no. You don't get personal taste... Pick any color you like

I've updated with the default settings which appear to use slightly more than 79 characters which is probably a sensible value.

Copy link
Contributor

@nbgl nbgl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’m finding Black-formatted code difficult to read.

It also appears to be incompatible with comment-style type annotations. (This could be fixed in a future version.)

However, I also recognise that it may reduce workload.

@@ -22,7 +22,9 @@ def __int_from_bytes(bytes, byteorder, signed=False):
:param byteorder: Either `'big'` or `'little'`.
"""
if signed:
raise NotImplementedError("Signed integers are not currently supported in this " "backport.")
raise NotImplementedError(
"Signed integers are not currently supported in this " "backport."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Black doesn’t recognise that these will be merged into one string so it doesn’t remove the superfluous " “.

@@ -93,5 +102,6 @@ def _p2_unicode_reader(unicode_csv_data, dialect=csv.excel, **kwargs):


unicode_reader = (
_p2_unicode_reader if sys.version_info < (3, 0) else csv.reader # Python 2 with hacky workarounds.
_p2_unicode_reader if sys.version_info
< (3, 0) else csv.reader # Python 2 with hacky workarounds.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find this much less readable than the previous form.

keys,
k,
l,
encoding, # type: Iterable[str] # type: Sequence[bytes] # type: int # type: int # type: str
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MyPy compatibility is broken here.

keys,
k,
l,
encoding, # type: Iterable[str] # type: Sequence[bytes] # type: int # type: int # type: str
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto regarding Mypy compatibility.

keys,
k,
l,
encoding, # type: Iterable[str] # type: Sequence[bytes] # type: int # type: int # type: str
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto regarding Mypy compatibility.

dataset, keys, schema # type: Iterable[Sequence[Text]] # type: Sequence[Sequence[bytes]] # type: Schema
dataset,
keys,
schema, # type: Iterable[Sequence[Text]] # type: Sequence[Sequence[bytes]] # type: Schema
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mypy.

'parameter "l" has to be a power of two for the BLAKE2 encoding, but was: {}'.format(
l
)
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is really ugly.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree - it looks better with the longer line length - 8254286#diff-f36426d58cf2623d909f2f77aae79799R183

clkhash/clk.py Outdated
from typing import AnyStr, Callable, Iterable, List, Optional, Sequence, TextIO, Tuple, TypeVar
from typing import (
AnyStr, Callable, Iterable, List, Optional, Sequence, TextIO, Tuple, TypeVar
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can get behind this!

case != self._DEFAULT_CASE
or min_length != self._DEFAULT_MIN_LENGTH
or max_length is not None
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is really hard to read.

@hardbyte
Copy link
Collaborator Author

Ok thanks for the review.

I think for now we can safely say we can't use black without changing how we annotate types for mypy.

@hardbyte hardbyte closed this Apr 13, 2018
@hardbyte hardbyte deleted the try-black branch June 26, 2018 11:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants