Skip to content

Commit

Permalink
some small tweaks for python 3 and lint (leapfrogonline#27)
Browse files Browse the repository at this point in the history
* some small tweaks for python 3 and lint

small tidy ups with base classes, dicts, unused variables, have run all tests and they pass

* Update AUTHORS

Added name at Brendan's suggestion
  • Loading branch information
marksmayo committed Oct 5, 2022
1 parent 75438c6 commit 20886b3
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 10 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ Goya Tomohiro
Xiaoqin Zhu
Stéphane Blondon
Pascal Corpet
Mark Mayo
2 changes: 1 addition & 1 deletion rstr/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from rstr.xeger import Xeger
from rstr.rstr_base import SameCharacterError as SameCharacterError
from rstr.rstr_base import SameCharacterError

Rstr = Xeger
_default_instance = Rstr()
Expand Down
9 changes: 4 additions & 5 deletions rstr/rstr_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def __call__(
}


class RstrBase(object):
class RstrBase():
'''Create random strings from a variety of alphabets.
The alphabets for printable(), uppercase(), lowercase(), digits(), and
Expand Down Expand Up @@ -125,7 +125,7 @@ class RstrBase(object):
'''

def __init__(self, _random: '_Random', **custom_alphabets: str) -> None:
super(RstrBase, self).__init__()
super().__init__()
self._random = _random
self._alphabets = dict(ALPHABETS)
for alpha_name, alphabet in custom_alphabets.items():
Expand All @@ -141,9 +141,8 @@ def add_alphabet(self, alpha_name: str, characters: str) -> None:
def __getattr__(self, attr: str) -> '_PartialRstrFunc':
if attr in self._alphabets:
return partial(self.rstr, self._alphabets[attr])
else:
message = 'Rstr instance has no attribute: {0}'.format(attr)
raise AttributeError(message)
message = f'Rstr instance has no attribute: {attr}'
raise AttributeError(message)

def sample_wr(self, population: Sequence[str], k: int) -> List[str]:
'''Samples k random elements (with replacement) from a population'''
Expand Down
4 changes: 2 additions & 2 deletions rstr/xeger.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ class Xeger(RstrBase):
def __init__(
self, _random: '_Random' = typing.cast('_Random', random), **custom_alphabets: str,
) -> None:
super(Xeger, self).__init__(_random, **custom_alphabets)
self._cache: Dict[str, str] = dict()
super().__init__(_random, **custom_alphabets)
self._cache: Dict[str, str] = {}
self._categories: Mapping[str, Callable[[], str]] = {
'category_digit': lambda: self._alphabets['digits'],
'category_not_digit': lambda: self._alphabets['nondigits'],
Expand Down
2 changes: 1 addition & 1 deletion tests/test_rstr.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@


def assert_matches(pattern: str, value: str) -> None:
errmsg = '{} does not match {}'.format(value, pattern)
errmsg = f'{value} does not match {pattern}'
assert re.match(pattern, value), errmsg


Expand Down
2 changes: 1 addition & 1 deletion tests/test_xeger.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def test_dot(self) -> None:
See: https://bitbucket.org/leapfrogdevelopment/rstr/issue/1/
'''
pattern = r'.+'
for i in range(100):
for _ in range(100):
assert re.match(pattern, self.rs.xeger(pattern))

def test_digit(self) -> None:
Expand Down

0 comments on commit 20886b3

Please sign in to comment.