Skip to content
This repository has been archived by the owner on Jan 13, 2023. It is now read-only.

PEP8 (WIP) #146

Closed

Conversation

HerrMuellerluedenscheid
Copy link
Contributor

@HerrMuellerluedenscheid HerrMuellerluedenscheid commented Jan 21, 2018

The PEP8 adoption could be done in one go and bundled in one pull request for all files. But it seems like it could cause quite some merge conflicts if it's not done in shortest time.

So, this is sort of a basis for discussion if the proposed style is fine (especially using 4 vs 2 spaces) for everybody. flake8 finishes errorless.

Marius Kriegerowski added 2 commits January 21, 2018 22:35
Copy link
Contributor

@todofixthis todofixthis left a comment

Choose a reason for hiding this comment

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

Hey Marius. Thanks for working on this!!

I left a few comments. I didn't quite understand a few of the changes, but I'm also not that familiar with flake8, so I'm genuinely curious here 😺


# :see: http://stackoverflow.com/a/2073599/
from pkg_resources import require
from pkg_resources import require # noqa
Copy link
Contributor

Choose a reason for hiding this comment

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

❔ I could see why the wildcard imports would need a # noqa, but does this import need one as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

require is not used. As I just read this is a warning of flake, not a PEP8 violation. But, if we include flake8 into travisCI this would be nice to get rid of. One way of handling this would be to explicitly export imported classes via __all__

Copy link
Contributor

@todofixthis todofixthis Jan 23, 2018

Choose a reason for hiding this comment

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

👍 Gotcha. Hm, that's odd. It does get used, but then it gets removed via del later on (I don't want it included in the iota namespace).

Eh, maybe the # noqa here is fine.

from iota import TransactionHash, TransactionTrytes, TryteString # noqa
from iota import TrytesCompatible # noqa
from iota.adapter import BaseAdapter, resolve_adapter # noqa
from iota.commands import BaseCommand, CustomCommand, core # noqa
Copy link
Contributor

Choose a reason for hiding this comment

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

❔ Do these imports need # noqa?

iota/api.py Outdated
trytes,
min_weight_magnitude=None
):
# type: (TransactionHash, TransactionHash, Iterable[TryteString], int) -> dict # noqa
Copy link
Contributor

Choose a reason for hiding this comment

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

❔ Does this guy need a # noqa?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

According to flake8, yes. The line has more than 80 character. I was not sure if these lines are somewhat interpreted by sphinx so I didn't break that line into two shorter ones. Would that be an option instead?

Copy link
Contributor

@todofixthis todofixthis Jan 23, 2018

Choose a reason for hiding this comment

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

👍 Gotcha. Those are type hints, used by some IDEs (e.g., PyCharm) for autocompletion, etc.

💡 It is possible to address the line length issue here, by doing this:

def attach_to_tangle(
    self,
    trunk_transaction,  # type: TransactionHash
    branch_transaction,  # type: TransactionHash
    trytes,  # type: Iterable[TryteString]
    min_weight_magnitude=None  # type: Optional[int]
):
    # type: (...) -> dict

See PEP-484 for more info.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That looks neat! 👍


References:
- https://github.com/iotaledger/wiki/blob/master/api-proposal.md#getbundle
""" # noqa
Copy link
Contributor

Choose a reason for hiding this comment

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

❔ Do these need # noqa?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Flake8 is really picky, I have to admint. line 535 has more than 80 chars... I think the picky-ness of flake can be tuned. I'll checkout if doc strings can be ignored, if # noqa is undesireable.

Copy link
Contributor

@todofixthis todofixthis Jan 23, 2018

Choose a reason for hiding this comment

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

👍 Hm. I guess that's fine. think it's useful to check line length on docstrings in general; if flake8 doesn't want to make exceptions for URLs, then we can live with this.

Anyway, the only alternatives I can think of are pretty awful, comparatively (split the URL into multiple lines, use URL shortener).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I also think URLs should be kept the way they are.
I'm going to update this PR asap

# type: (AdapterSpec, bool) -> None
"""
:param adapter:
URI string or BaseAdapter instance.
Copy link
Contributor

Choose a reason for hiding this comment

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

❔ To be consistent, should we also use 4-space indents inside docstrings?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't know. Sphinx doesn't respect formatting here anyway, right? Ah, let's make it 4 ok?

@HerrMuellerluedenscheid HerrMuellerluedenscheid mentioned this pull request Jan 24, 2018
@HerrMuellerluedenscheid
Copy link
Contributor Author

Going to close this PR in favor of #147

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants