diff --git a/.flake8 b/.flake8 new file mode 100644 index 0000000..934fdea --- /dev/null +++ b/.flake8 @@ -0,0 +1,3 @@ +[flake8] +ignore = E501,W503 +max-line-length = 88 diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index cdf60ff..f7d584e 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -17,9 +17,8 @@ jobs: python-version: ${{ matrix.python-version }} architecture: x64 - run: python -m pip install flake8 nox poetry - - run: flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics + - run: flake8 . --count --show-source --statistics - run: python -m nox env: OS: ${{ matrix.os }} PYTHON: ${{ matrix.python-version }} - diff --git a/pywhat/__init__.py b/pywhat/__init__.py index 8be36c6..859f02f 100644 --- a/pywhat/__init__.py +++ b/pywhat/__init__.py @@ -7,13 +7,11 @@ tags = AvailableTags().get_tags() pywhat_tags = tags # left for backward compatibility purposes -_contents = ["Identifier", "Distribution", "tags", "pywhat_tags", "Keys", "Filter"] +__all__ = ["Identifier", "Distribution", "tags", "pywhat_tags", "Keys", "Filter"] -__all__ = _contents - del AvailableTags, filter def __dir__(): - return _contents + ["__version__"] + return __all__ + ["__version__"] diff --git a/pywhat/filter.py b/pywhat/filter.py index aa47c00..30fe5f6 100644 --- a/pywhat/filter.py +++ b/pywhat/filter.py @@ -91,14 +91,11 @@ def __len__(self): return len(self._dict) def __contains__(self, item): - try: - return ( - self["MinRarity"] <= item["Rarity"] <= self["MaxRarity"] - and set(item["Tags"]) & self["Tags"] - and not set(item["Tags"]) & self["ExcludeTags"] - ) - except: - return False + return ( + self["MinRarity"] <= item["Rarity"] <= self["MaxRarity"] + and set(item["Tags"]) & self["Tags"] + and not set(item["Tags"]) & self["ExcludeTags"] + ) def setdefault(self, key, default=None): return self._dict.setdefault(key, default) diff --git a/pywhat/helper.py b/pywhat/helper.py index 233de6b..581ab93 100644 --- a/pywhat/helper.py +++ b/pywhat/helper.py @@ -86,9 +86,15 @@ def issubset(self, other): class Keys(Enum): - NAME = lambda match: match["Regex Pattern"]["Name"] - RARITY = lambda match: match["Regex Pattern"]["Rarity"] - MATCHED = lambda match: match["Matched"] + def NAME(match): + return match["Regex Pattern"]["Name"] + + def RARITY(match): + return match["Regex Pattern"]["Rarity"] + + def MATCHED(match): + return match["Matched"] + NONE = auto() diff --git a/pywhat/what.py b/pywhat/what.py index cb6c91d..9ed31da 100644 --- a/pywhat/what.py +++ b/pywhat/what.py @@ -222,7 +222,7 @@ def main(**kwargs): %t - tags (in 'tag1, tag2 ...' format) - If you want to print '%' or '\' character - escape it: '\%', '\\'. + If you want to print '%' or '\\' character - escape it: '\\%', '\\\\'. Examples: diff --git a/tests/test_filtration.py b/tests/test_filtration.py index 44e50fd..b7461c4 100644 --- a/tests/test_filtration.py +++ b/tests/test_filtration.py @@ -101,7 +101,7 @@ def test_distribution6(): def test_distribution7(): with pytest.raises(InvalidTag): - dist = Distribution({"Tags": "Media", "MinRarity": 0.7}) + Distribution({"Tags": "Media", "MinRarity": 0.7}) def test_filter(): diff --git a/tests/test_identifier.py b/tests/test_identifier.py index 1fd0770..b90801c 100644 --- a/tests/test_identifier.py +++ b/tests/test_identifier.py @@ -2,7 +2,7 @@ from pywhat import identifier from pywhat.filter import Distribution, Filter -from pywhat.helper import Keys, load_regexes +from pywhat.helper import Keys r = identifier.Identifier() @@ -99,7 +99,7 @@ def test_identifier_sorting6(): def test_only_text(): out = r.identify("fixtures/file") - assert None == out["Regexes"] + assert out["Regexes"] is None out = r.identify("THM{7281j}}", only_text=True) assert "TryHackMe Flag Format" in out["Regexes"]["text"][0]["Regex Pattern"]["Name"] diff --git a/tests/test_regex_identifier.py b/tests/test_regex_identifier.py index be112bc..c441a1a 100644 --- a/tests/test_regex_identifier.py +++ b/tests/test_regex_identifier.py @@ -1,6 +1,3 @@ -import re -from typing import List, Tuple - import pytest from pywhat import regex_identifier