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

Fix Flake8 #428

Closed
wants to merge 8 commits into from
Closed

Fix Flake8 #428

wants to merge 8 commits into from

Conversation

hugovk
Copy link
Member

@hugovk hugovk commented Nov 10, 2019

Fixes #401.

Includes #427, the first two commits. The others are new to this PR.

Flake8 found one bug: e3b445c

And one bit of old Python 2 code: 77c5488

Locally:

# Install
pip install -U flake8

# Run
flake8

Also run as part of:

pre-commit run --all-files

# Or
pre-commit run --all-files flake8

# Or
tox -e lint

Also run as part of the CI lint jobs.

@@ -123,7 +123,7 @@ def export_set_as_simple_table(cls, dataset, column_widths=None):
lines = []
wrapper = TextWrapper()
if column_widths is None:
column_widths = _get_column_widths(dataset, pad_len=2)
column_widths = cls._get_column_widths(dataset, pad_len=2)
Copy link
Contributor

Choose a reason for hiding this comment

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

Would be great to have a separate PR for this, with a test to complete coverage of that line.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think we could probably remove this whole if block. I don't see how column_widths can be None.

The default value is None in the method definition:

    def export_set_as_simple_table(cls, dataset, column_widths=None):

But it's only called from one place in export_set, and it includes a variable for column_widths, so it won't default to None:

        if use_simple_table and not force_grid:
            return cls.export_set_as_simple_table(dataset, column_widths)
        else:
            return cls.export_set_as_grid_table(dataset, column_widths)

Earlier in that method, it is set as:

        column_widths = cls._get_column_widths(dataset, max_table_width)

Which will always return a list:

        column_widths = [max(w, l) for w, l in zip(column_widths, word_lens)]
        return column_widths

A similar thing happens for the similar if block in export_set_as_grid_table.

These are all in _rst.py, the underscore denoting a private, internal code, and not part of the API.

What do you think?

Copy link
Contributor

@claudep claudep Nov 11, 2019

Choose a reason for hiding this comment

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

Not sure, as the method itself is not prefixed with underscore, so if someone could very well call something like fmt = registry.get_format('rst'); fmt.export_set_as_simple_table(dataset) without breaking private rules. No strong opinion, but I would tend to fix and test.

Copy link
Member Author

Choose a reason for hiding this comment

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

There we go! #433

@hugovk
Copy link
Member Author

hugovk commented Nov 26, 2019

Let's not worry about Black for now, it's not essential.

@hugovk hugovk closed this Nov 26, 2019
@hugovk hugovk deleted the flake8 branch November 26, 2019 16:04
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.

Consider enforcing flake8, black and isort
2 participants