diff --git a/.github/workflows/linting.yml b/.github/workflows/linting.yml index 29d31dd..c731efe 100644 --- a/.github/workflows/linting.yml +++ b/.github/workflows/linting.yml @@ -19,3 +19,5 @@ jobs: run: isort . - name: black run: black . + - name: flake8 + run: flake8 . diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 88e3b32..b38c165 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -4,7 +4,7 @@ * Add `sort_dict` option (thanks @gergelyk). * Use `pytest` instead of `nose` (thanks @pgajdos). * Use GitHub Actions instead of Travis. - * Linting (isort, black, etc.). + * Linting: `isort`, `black`, `flake8`. Wrapping at 100 lines from the previous 80. * Other file and folder restructuring. diff --git a/pprintpp/__init__.py b/pprintpp/__init__.py index af12554..c9e078e 100644 --- a/pprintpp/__init__.py +++ b/pprintpp/__init__.py @@ -13,7 +13,8 @@ __all__ = ["pprint", "pformat", "isreadable", "isrecursive", "saferepr", "PrettyPrinter"] -chr_to_ascii = lambda x: ascii(x)[1:-1] +def chr_to_ascii(c): + return ascii(c)[1:-1] def _sorted(iterable): @@ -42,44 +43,44 @@ def getvalue(self): # Source: http://www.unicode.org/reports/tr44/#GC_Values_Table # fmt: off unicode_printable_categories = { - "Lu": 1, # Uppercase_Letter an uppercase letter - "Ll": 1, # Lowercase_Letter a lowercase letter - "Lt": 1, # Titlecase_Letter a digraphic character, with first part uppercase - "LC": 1, # Cased_Letter Lu | Ll | Lt - "Lm": 0, # Modifier_Letter a modifier letter - "Lo": 1, # Other_Letter other letters, including syllables and ideographs - "L": 1, # Letter Lu | Ll | Lt | Lm | Lo - "Mn": 0, # Nonspacing_Mark a nonspacing combining mark (zero advance width) - "Mc": 0, # Spacing_Mark a spacing combining mark (positive advance width) - "Me": 0, # Enclosing_Mark an enclosing combining mark - "M": 1, # Mark Mn | Mc | Me - "Nd": 1, # Decimal_Number a decimal digit - "Nl": 1, # Letter_Number a letterlike numeric character - "No": 1, # Other_Number a numeric character of other type - "N": 1, # Number Nd | Nl | No - "Pc": 1, # Connector_Punctuation a connecting punctuation mark, like a tie - "Pd": 1, # Dash_Punctuation a dash or hyphen punctuation mark - "Ps": 1, # Open_Punctuation an opening punctuation mark (of a pair) - "Pe": 1, # Close_Punctuation a closing punctuation mark (of a pair) - "Pi": 1, # Initial_Punctuation an initial quotation mark - "Pf": 1, # Final_Punctuation a final quotation mark - "Po": 1, # Other_Punctuation a punctuation mark of other type - "P": 1, # Punctuation Pc | Pd | Ps | Pe | Pi | Pf | Po - "Sm": 1, # Math_Symbol a symbol of mathematical use - "Sc": 1, # Currency_Symbol a currency sign - "Sk": 1, # Modifier_Symbol a non-letterlike modifier symbol - "So": 1, # Other_Symbol a symbol of other type - "S": 1, # Symbol Sm | Sc | Sk | So - "Zs": 0, # Space_Separator a space character (of various non-zero widths) - "Zl": 0, # Line_Separator U+2028 LINE SEPARATOR only - "Zp": 0, # Paragraph_Separator U+2029 PARAGRAPH SEPARATOR only - "Z": 1, # Separator Zs | Zl | Zp - "Cc": 0, # Control a C0 or C1 control code - "Cf": 0, # Format a format control character - "Cs": 0, # Surrogate a surrogate code point - "Co": 0, # Private_Use a private-use character - "Cn": 0, # Unassigned a reserved unassigned code point or a noncharacter - "C": 0, # Other Cc | Cf | Cs | Co | Cn + "Lu": 1, # Uppercase_Letter an uppercase letter + "Ll": 1, # Lowercase_Letter a lowercase letter + "Lt": 1, # Titlecase_Letter a digraphic character, with first part uppercase + "LC": 1, # Cased_Letter Lu | Ll | Lt + "Lm": 0, # Modifier_Letter a modifier letter + "Lo": 1, # Other_Letter other letters, including syllables and ideographs + "L": 1, # Letter Lu | Ll | Lt | Lm | Lo + "Mn": 0, # Nonspacing_Mark a nonspacing combining mark (zero advance width) + "Mc": 0, # Spacing_Mark a spacing combining mark (positive advance width) + "Me": 0, # Enclosing_Mark an enclosing combining mark + "M": 1, # Mark Mn | Mc | Me + "Nd": 1, # Decimal_Number a decimal digit + "Nl": 1, # Letter_Number a letterlike numeric character + "No": 1, # Other_Number a numeric character of other type + "N": 1, # Number Nd | Nl | No + "Pc": 1, # Connector_Punctuation a connecting punctuation mark, like a tie + "Pd": 1, # Dash_Punctuation a dash or hyphen punctuation mark + "Ps": 1, # Open_Punctuation an opening punctuation mark (of a pair) + "Pe": 1, # Close_Punctuation a closing punctuation mark (of a pair) + "Pi": 1, # Initial_Punctuation an initial quotation mark + "Pf": 1, # Final_Punctuation a final quotation mark + "Po": 1, # Other_Punctuation a punctuation mark of other type + "P": 1, # Punctuation Pc | Pd | Ps | Pe | Pi | Pf | Po + "Sm": 1, # Math_Symbol a symbol of mathematical use + "Sc": 1, # Currency_Symbol a currency sign + "Sk": 1, # Modifier_Symbol a non-letterlike modifier symbol + "So": 1, # Other_Symbol a symbol of other type + "S": 1, # Symbol Sm | Sc | Sk | So + "Zs": 0, # Space_Separator a space character (of various non-zero widths) + "Zl": 0, # Line_Separator U+2028 LINE SEPARATOR only + "Zp": 0, # Paragraph_Separator U+2029 PARAGRAPH SEPARATOR only + "Z": 1, # Separator Zs | Zl | Zp + "Cc": 0, # Control a C0 or C1 control code + "Cf": 0, # Format a format control character + "Cs": 0, # Surrogate a surrogate code point + "Co": 0, # Private_Use a private-use character + "Cn": 0, # Unassigned a reserved unassigned code point or a noncharacter + "C": 0, # Other Cc | Cf | Cs | Co | Cn } # fmt: on diff --git a/requirements-dev.txt b/requirements-dev.txt index d33adb1..ce1e046 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,2 +1,3 @@ black==22.3.0 +flake8==4.0.1 isort==5.10.1 diff --git a/setup.cfg b/setup.cfg index 2a9acf1..72b9ed6 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,2 +1,6 @@ [bdist_wheel] universal = 1 + +[flake8] +exclude = .git,.github,.venv,__pycache__ +max-line-length = 100 diff --git a/tests/test_pprintpp.py b/tests/test_pprintpp.py index 68d53e9..d0fd303 100644 --- a/tests/test_pprintpp.py +++ b/tests/test_pprintpp.py @@ -5,11 +5,11 @@ from contextlib import redirect_stdout import pytest +import pprintpp as p +from pprintpp import defaultdict sys.path.append("pp/") -import pp -import pprintpp as p -from pprintpp import Counter, OrderedDict, defaultdict +import pp # noqa: E402 module level import not at top of file def test_pp(): @@ -47,9 +47,10 @@ def test_module_like(): uni_safe = "\xe9 \u6f02 \u0e4f \u2661" uni_unsafe = "\u200a \u0302 \n" -slashed = lambda s: u"'%s'" % ( - s.encode("ascii", "backslashreplace").decode("ascii").replace("\n", "\\n") -) + + +def slashed(s): + return "'%s'" % s.encode("ascii", "backslashreplace").decode("ascii").replace("\n", "\\n") @pytest.mark.skip('fix')