Skip to content

Commit

Permalink
Merge branch 'release/3.9.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
wolph committed Nov 26, 2024
2 parents 68c9703 + 0a76c1c commit 798bfa2
Show file tree
Hide file tree
Showing 10 changed files with 148 additions and 139 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
timeout-minutes: 4
strategy:
matrix:
python-version: ['3.9', '3.10', '3.11', '3.12'] # Maybe soon?, '3.13']
python-version: ['pypy3.9', 'pypy3.10', '3.9', '3.10', '3.11', '3.12'] # Maybe soon?, '3.13']

steps:
- uses: actions/checkout@v4
Expand Down
24 changes: 12 additions & 12 deletions _python_utils_tests/test_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ async def test_aio_timeout_generator(
@pytest.mark.parametrize(
'timeout,interval,interval_multiplier,maximum_interval,iterable,result',
[
(0.01, 0.006, 0.5, 0.01, 'abc', 'c'),
(0.01, 0.007, 0.5, 0.01, itertools.count, 2),
(0.01, 0.007, 0.5, 0.01, itertools.count(), 2),
(0.01, 0.006, 1.0, None, 'abc', 'c'),
(0.1, 0.06, 0.5, 0.1, 'abc', 'c'),
(0.1, 0.07, 0.5, 0.1, itertools.count, 2),
(0.1, 0.07, 0.5, 0.1, itertools.count(), 2),
(0.1, 0.06, 1.0, None, 'abc', 'c'),
(
timedelta(seconds=0.01),
timedelta(seconds=0.006),
timedelta(seconds=0.1),
timedelta(seconds=0.06),
2.0,
timedelta(seconds=0.01),
timedelta(seconds=0.1),
itertools.count,
2,
),
Expand Down Expand Up @@ -91,28 +91,28 @@ async def test_aio_generator_timeout_detector() -> None:

async def generator() -> types.AsyncGenerator[int, None]:
for i in range(10):
await asyncio.sleep(i / 100.0)
await asyncio.sleep(i / 20.0)
yield i

detector = python_utils.aio_generator_timeout_detector
# Test regular timeout with reraise
with pytest.raises(asyncio.TimeoutError):
async for i in detector(generator(), 0.05):
async for i in detector(generator(), 0.25):
pass

# Test regular timeout with clean exit
async for i in detector(generator(), 0.05, on_timeout=None):
async for i in detector(generator(), 0.25, on_timeout=None):
pass

assert i == 4

# Test total timeout with reraise
with pytest.raises(asyncio.TimeoutError):
async for i in detector(generator(), total_timeout=0.1):
async for i in detector(generator(), total_timeout=0.5):
pass

# Test total timeout with clean exit
async for i in detector(generator(), total_timeout=0.1, on_timeout=None):
async for i in detector(generator(), total_timeout=0.5, on_timeout=None):
pass

assert i == 4
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ pythonVersion = '3.9'
[tool.mypy]
strict = true
check_untyped_defs = true
files = ['python_utils', '_python_utils_tests', 'setup.py']

[[tool.mypy.overrides]]
module = '_python_utils_tests.*'
2 changes: 1 addition & 1 deletion python_utils/__about__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@
)
__url__: str = 'https://github.com/WoLpH/python-utils'
# Omit type info due to automatic versioning script
__version__ = '3.9.0'
__version__ = '3.9.1'
60 changes: 30 additions & 30 deletions python_utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,44 +83,44 @@
)

__all__ = [
'CastedDict',
'LazyCastedDict',
'Logged',
'LoggerBase',
'UniqueList',
'abatcher',
'acount',
'aio',
'generators',
'aio_generator_timeout_detector',
'aio_generator_timeout_detector_decorator',
'aio_timeout_generator',
'batcher',
'camel_to_underscore',
'converters',
'decorators',
'delta_to_seconds',
'delta_to_seconds_or_none',
'format_time',
'formatters',
'generators',
'get_terminal_size',
'import_',
'import_global',
'listify',
'logger',
'terminal',
'time',
'types',
'to_int',
'to_float',
'to_unicode',
'to_str',
'scale_1024',
'raise_exception',
'remap',
'reraise',
'scale_1024',
'set_attributes',
'listify',
'camel_to_underscore',
'timesince',
'import_global',
'get_terminal_size',
'terminal',
'time',
'timedelta_to_seconds',
'format_time',
'timeout_generator',
'acount',
'abatcher',
'batcher',
'aio_timeout_generator',
'aio_generator_timeout_detector_decorator',
'aio_generator_timeout_detector',
'delta_to_seconds',
'delta_to_seconds_or_none',
'reraise',
'raise_exception',
'Logged',
'LoggerBase',
'CastedDict',
'LazyCastedDict',
'UniqueList',
'timesince',
'to_float',
'to_int',
'to_str',
'to_unicode',
'types',
]
10 changes: 5 additions & 5 deletions python_utils/formatters.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,11 @@ def timesince(

output: types.List[str] = []
for period, singular, plural in periods:
if int(period):
if int(period) == 1:
output.append('%d %s' % (period, singular))
else:
output.append('%d %s' % (period, plural))
int_period = int(period)
if int_period == 1:
output.append(f'{int_period} {singular}')
elif int_period:
output.append(f'{int_period} {plural}')

if output:
return f'{" and ".join(output[:2])} ago'
Expand Down
168 changes: 84 additions & 84 deletions python_utils/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,128 +54,128 @@
]

__all__ = [
'OptionalScope',
'Number',
'DecimalNumber',
'delta_type',
'timestamp_type',
'IO',
'TYPE_CHECKING',
# ABCs (from collections.abc).
'AbstractSet',
# The types from the typing module.
# Super-special typing primitives.
'Annotated',
'Any',
# One-off things.
'AnyStr',
'AsyncContextManager',
'AsyncGenerator',
'AsyncGeneratorType',
'AsyncIterable',
'AsyncIterator',
'Awaitable',
# Other concrete types.
'BinaryIO',
'BuiltinFunctionType',
'BuiltinMethodType',
'ByteString',
'Callable',
# Concrete collection types.
'ChainMap',
'ClassMethodDescriptorType',
'ClassVar',
'CodeType',
'Collection',
'Concatenate',
'Container',
'ContextManager',
'Coroutine',
'CoroutineType',
'Counter',
'DecimalNumber',
'DefaultDict',
'Deque',
'Dict',
'DynamicClassAttribute',
'Final',
'ForwardRef',
'FrameType',
'FrozenSet',
# Types from the `types` module.
'FunctionType',
'Generator',
'GeneratorType',
'Generic',
'Literal',
'SupportsIndex',
'Optional',
'ParamSpec',
'ParamSpecArgs',
'ParamSpecKwargs',
'Protocol',
'Tuple',
'Type',
'TypeVar',
'Union',
# ABCs (from collections.abc).
'AbstractSet',
'ByteString',
'Container',
'ContextManager',
'GetSetDescriptorType',
'Hashable',
'ItemsView',
'Iterable',
'Iterator',
'KeysView',
'LambdaType',
'List',
'Literal',
'Mapping',
'MappingProxyType',
'MappingView',
'Match',
'MemberDescriptorType',
'MethodDescriptorType',
'MethodType',
'MethodWrapperType',
'ModuleType',
'MutableMapping',
'MutableSequence',
'MutableSet',
'Sequence',
'Sized',
'ValuesView',
'Awaitable',
'AsyncIterator',
'AsyncIterable',
'Coroutine',
'Collection',
'AsyncGenerator',
'AsyncContextManager',
'NamedTuple', # Not really a type.
'NewType',
'NoReturn',
'Number',
'Optional',
'OptionalScope',
'OrderedDict',
'ParamSpec',
'ParamSpecArgs',
'ParamSpecKwargs',
'Pattern',
'Protocol',
# Structural checks, a.k.a. protocols.
'Reversible',
'Sequence',
'Set',
'SimpleNamespace',
'Sized',
'SupportsAbs',
'SupportsBytes',
'SupportsComplex',
'SupportsFloat',
'SupportsIndex',
'SupportsIndex',
'SupportsInt',
'SupportsRound',
# Concrete collection types.
'ChainMap',
'Counter',
'Deque',
'Dict',
'DefaultDict',
'List',
'OrderedDict',
'Set',
'FrozenSet',
'NamedTuple', # Not really a type.
'TypedDict', # Not really a type.
'Generator',
# Other concrete types.
'BinaryIO',
'IO',
'Match',
'Pattern',
'Text',
'TextIO',
# One-off things.
'AnyStr',
'TracebackType',
'TracebackType',
'Tuple',
'Type',
'TypeAlias',
'TypeGuard',
'TypeVar',
'TypedDict', # Not really a type.
'Union',
'ValuesView',
'WrapperDescriptorType',
'cast',
'coroutine',
'delta_type',
'final',
'get_args',
'get_origin',
'get_type_hints',
'is_typeddict',
'NewType',
'new_class',
'no_type_check',
'no_type_check_decorator',
'NoReturn',
'overload',
'runtime_checkable',
'Text',
'TYPE_CHECKING',
'TypeAlias',
'TypeGuard',
'TracebackType',
# Types from the `types` module.
'FunctionType',
'LambdaType',
'CodeType',
'MappingProxyType',
'SimpleNamespace',
'GeneratorType',
'CoroutineType',
'AsyncGeneratorType',
'MethodType',
'BuiltinFunctionType',
'BuiltinMethodType',
'WrapperDescriptorType',
'MethodWrapperType',
'MethodDescriptorType',
'ClassMethodDescriptorType',
'ModuleType',
'TracebackType',
'FrameType',
'GetSetDescriptorType',
'MemberDescriptorType',
'new_class',
'resolve_bases',
'prepare_class',
'DynamicClassAttribute',
'coroutine',
'resolve_bases',
'runtime_checkable',
'timestamp_type',
]
Loading

0 comments on commit 798bfa2

Please sign in to comment.