Skip to content

Commit

Permalink
Merge pull request #195 from jyooru/flake8
Browse files Browse the repository at this point in the history
flake8
  • Loading branch information
bee-san committed Oct 19, 2021
2 parents d6c6c00 + 4342bdc commit 75e38c6
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 24 deletions.
3 changes: 3 additions & 0 deletions .flake8
@@ -0,0 +1,3 @@
[flake8]
ignore = E501,W503
max-line-length = 88
3 changes: 1 addition & 2 deletions .github/workflows/main.yaml
Expand Up @@ -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 }}

6 changes: 2 additions & 4 deletions pywhat/__init__.py
Expand Up @@ -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__"]
13 changes: 5 additions & 8 deletions pywhat/filter.py
Expand Up @@ -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)
Expand Down
12 changes: 9 additions & 3 deletions pywhat/helper.py
Expand Up @@ -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()


Expand Down
2 changes: 1 addition & 1 deletion pywhat/what.py
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_filtration.py
Expand Up @@ -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():
Expand Down
4 changes: 2 additions & 2 deletions tests/test_identifier.py
Expand Up @@ -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()

Expand Down Expand Up @@ -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"]
Expand Down
3 changes: 0 additions & 3 deletions tests/test_regex_identifier.py
@@ -1,6 +1,3 @@
import re
from typing import List, Tuple

import pytest

from pywhat import regex_identifier
Expand Down

0 comments on commit 75e38c6

Please sign in to comment.