8000 Drop support for deprecated Python version 3.8 by mdomke · Pull Request #908 · mongomock/mongomock · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Drop support for deprecated Python version 3.8 #908

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Nov 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/lint-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
Expand Down
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [4.4.0] - tbd
### Added
- Add support for Python 3.13

### Changed
- Remove legacy syntax constructs using `pyupgrade --py39-plus`

### Removed
- Remove support for deprecated Python version 3.8


## [4.3.0] - 2024-11-16
### Added
- Support for aggregation pipelines in updates [@maximkir-fl](https://github.com/maximkir-fl)
Expand All @@ -27,5 +38,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Remove support for deprecated Python versions (everything prior to 3.8)


[4.4.0]: https://github.com/mongomock/mongomock/compare/4.3.0...4.4.0
[4.3.0]: https://github.com/mongomock/mongomock/compare/4.2.0...4.3.0
[4.2.0]: https://github.com/mongomock/mongomock/compare/4.1.3...4.2.0
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ RUN apt-get update \
libncurses5-dev \
pipx

ENV PATH /root/.local/bin:${PATH}
ENV PATH=/root/.local/bin:${PATH}
RUN pipx ensurepath && pipx install hatch
RUN hatch python install 3.8 3.9 3.10 3.11 3.12 pypy3.10
RUN hatch python install 3.9 3.10 3.11 3.12 3.13 pypy3.10
2 changes: 1 addition & 1 deletion hatch.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ matrix.pymongo.extra-dependencies = [
]

[[envs.hatch-test.matrix]]
python = ["3.8", "3.9", "3.10", "3.11", "3.12", "pypy3"]
python = ["3.9", "3.10", "3.11", "3.12", "3.13", "pypy3"]
pymongo = ["3", "4", "none"]

[envs.cov]
Expand Down
4 changes: 2 additions & 2 deletions mongomock/aggregate.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ def _handle_arithmetic_operator(self, operator, values):
return res

assert isinstance(values, (tuple, list)), \
"Parameter to {} must evaluate to a list, got '{}'".format(operator, type(values))
f"Parameter to {operator} must evaluate to a list, got '{type(values)}'"

parsed_values = list(self.parse_many(values))
assert parsed_values, '%s must have at least one parameter' % operator
Expand Down Expand Up @@ -1449,7 +1449,7 @@ def _combine_projection_spec(filter_list, original_filter, prefix=''):
filter_dict[field] = filter_dict.get(field, []) + [subkey]

return collections.OrderedDict(
(k, _combine_projection_spec(v, original_filter, prefix='{}{}.'.format(prefix, k)))
(k, _combine_projection_spec(v, original_filter, prefix=f'{prefix}{k}.'))
for k, v in filter_dict.items()
)

Expand Down
2 changes: 1 addition & 1 deletion mongomock/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ def _combine_projection_spec(projection_fields_spec):
if not isinstance(tmp_spec.get(base_field), dict):
if base_field in tmp_spec:
raise OperationFailure(
'Path collision at {} remaining portion {}'.format(f, new_field))
f'Path collision at {f} remaining portion {new_field}')
tmp_spec[base_field] = OrderedDict()
tmp_spec[base_field][new_field] = v

Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ authors = [
{ name = "Martin Domke", email = "mail@martindomke.net" },
{ name = "Pascal Corpet", email = "pascal@corpet.net" },
]
requires-python = ">=3.9"
classifiers = [
"License :: OSI Approved :: ISC License (ISCL)",
"Topic :: Database",
Expand All @@ -24,11 +25,11 @@ classifiers = [
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
]
dependencies = [
"packaging",
Expand All @@ -50,7 +51,6 @@ source = "vcs"
[tool.hatch.build.targets.wheel]
packages = ["mongomock"]


[tool.pylint."messages control"]
disable = [
"missing-docstring",
Expand Down
6 changes: 3 additions & 3 deletions tests/diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
_HAVE_PYMONGO = False


class _NO_VALUE(object):
class _NO_VALUE:
pass


Expand Down Expand Up @@ -65,10 +65,10 @@ def diff(a, b, path=None):
return [(path[:], a, b)]
if not isinstance(a, _SUPPORTED_TYPES):
raise NotImplementedError(
'Unsupported diff type: {0}'.format(type(a))) # pragma: no cover
f'Unsupported diff type: {type(a)}') # pragma: no cover
if not isinstance(b, _SUPPORTED_TYPES):
raise NotImplementedError(
'Unsupported diff type: {0}'.format(type(b))) # pragma: no cover
f'Unsupported diff type: {type(b)}') # pragma: no cover
if a != b:
return [(path[:], a, b)]
return []
Expand Down
20 changes: 10 additions & 10 deletions tests/multicollection.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
_COMPARE_EXCEPTIONS = 'exceptions'


class MultiCollection(object):
class MultiCollection:

def __init__(self, conns):
super(MultiCollection, self).__init__()
super().__init__()
self.conns = conns.copy()
self.do = Foreach(self.conns, compare=False)
self.compare = Foreach(self.conns, compare=True)
Expand All @@ -20,7 +20,7 @@ def __init__(self, conns):
self.compare_exceptions = Foreach(self.conns, compare=_COMPARE_EXCEPTIONS)


class Foreach(object):
class Foreach:

def __init__(self, objs, compare, ignore_order=False,
method_result_decorators=()):
Expand Down Expand Up @@ -51,7 +51,7 @@ def __call__(self, *decorators):
self.___decorators + list(decorators))


class ForeachMethod(object):
class ForeachMethod:

def __init__(self, objs, compare, ignore_order, method_name, decorators, sort_by):
self.___objs = objs
Expand All @@ -76,15 +76,15 @@ def _get_exception_type(self, obj, args, kwargs, name):

def __call__(self, *args, **kwargs):
if self.___compare == _COMPARE_EXCEPTIONS:
results = dict(
(name, self._get_exception_type(obj, args, kwargs, name=name))
results = {
name: self._get_exception_type(obj, args, kwargs, name=name)
for name, obj in self.___objs.items()
)
}
else:
results = dict(
(name, self._call(obj, args, kwargs))
results = {
name: self._call(obj, args, kwargs)
for name, obj in self.___objs.items()
)
}
if self.___compare:
_assert_no_diff(results, ignore_order=self.___ignore_order, sort_by=self.___sort_by)
return results
Expand Down
12 changes: 6 additions & 6 deletions tests/test__bulk_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class BulkOperationsTest(TestCase):
test_with_pymongo = False

def setUp(self):
super(BulkOperationsTest, self).setUp()
super().setUp()
if self.test_with_pymongo:
self.client = pymongo.MongoClient(host=os.environ.get('TEST_MONGO_HOST', 'localhost'))
else:
Expand All @@ -48,14 +48,14 @@ def __check_result(self, result, **expecting_values):
if self.test_with_pymongo and key == 'nModified' and has_val is None:
# ops, real pymongo did not returned 'nModified' key!
continue
self.assertFalse(has_val is None, "Missed key '%s' in result: %s" % (key, result))
self.assertFalse(has_val is None, f"Missed key '{key}' in result: {result}")
if exp_val:
self.assertEqual(
exp_val, has_val, 'Invalid result %s=%s (but expected value=%s)' % (
exp_val, has_val, 'Invalid result {}={} (but expected value={})'.format(
key, has_val, exp_val))
else:
self.assertFalse(
bool(has_val), 'Received unexpected value %s = %s' % (key, has_val))
bool(has_val), f'Received unexpected value {key} = {has_val}')

def __execute_and_check_result(self, write_concern=None, **expecting_result):
result = self.bulk_op.execute(write_concern=write_concern)
Expand All @@ -64,7 +64,7 @@ def __execute_and_check_result(self, write_concern=None, **expecting_result):
def __check_number_of_elements(self, count):
has_count = self.db.collection.count()
self.assertEqual(
has_count, count, 'There is %s documents but there should be %s' % (has_count, count))
has_count, count, f'There is {has_count} documents but there should be {count}')

def test__insert(self):
self.bulk_op.insert({'a': 1, 'b': 2})
Expand Down Expand Up @@ -188,7 +188,7 @@ class BulkOperationsWithPymongoTest(BulkOperationsTest):
class CollectionComparisonTest(TestCase):

def setUp(self):
super(CollectionComparisonTest, self).setUp()
super().setUp()
self.fake_conn = mongomock.MongoClient()
self.mongo_conn = pymongo.MongoClient(host=os.environ.get('TEST_MONGO_HOST', 'localhost'))
self.db_name = 'mongomock___testing_db'
Expand Down
2 changes: 1 addition & 1 deletion tests/test__client_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
_HAVE_MOCK = True
except ImportError:
try:
import mock
from unittest import mock

Check warning on line 11 in tests/test__client_api.py

View check run for this annotation

Codecov / codecov/patch

tests/test__client_api.py#L11

Added line #L11 was not covered by tests
_HAVE_MOCK = True
except ImportError:
_HAVE_MOCK = False
Expand Down
32 changes: 16 additions & 16 deletions tests/test__collection_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def dst(self, dt):
class CollectionAPITest(TestCase):

def setUp(self):
super(CollectionAPITest, self).setUp()
super().setUp()
self.client = mongomock.MongoClient()
self.db = self.client['somedb']

Expand All @@ -64,7 +64,7 @@ def test__get_subcollections(self):
self.assertEqual(self.db.a.b.full_name, 'somedb.a.b')
self.assertEqual(self.db.a.b.name, 'a.b')

self.assertEqual(set(self.db.list_collection_names()), set(['a.b']))
self.assertEqual(set(self.db.list_collection_names()), {'a.b'})

def test__get_subcollections_by_attribute_underscore(self):
with self.assertRaises(AttributeError) as err_context:
Expand Down Expand Up @@ -110,7 +110,7 @@ def test__drop_collection(self):
self.db.drop_collection('b')
self.db.drop_collection('b')
self.db.drop_collection(self.db.c)
self.assertEqual(set(self.db.list_collection_names()), set(['a']))
self.assertEqual(set(self.db.list_collection_names()), {'a'})

col = self.db.a
r = col.insert_one({'aa': 'bb'}).inserted_id
Expand Down Expand Up @@ -181,7 +181,7 @@ def test__distinct_array_field(self):
self.db.collection.insert_many(
[{'f1': ['v1', 'v2', 'v1']}, {'f1': ['v2', 'v3']}])
cursor = self.db.collection.find()
self.assertEqual(set(cursor.distinct('f1')), set(['v1', 'v2', 'v3']))
self.assertEqual(set(cursor.distinct('f1')), {'v1', 'v2', 'v3'})

def test__distinct_array_nested_field(self):
self.db.collection.insert_one({'f1': [{'f2': 'v'}, {'f2': 'w'}]})
Expand All @@ -208,7 +208,7 @@ def test__distinct_filter_field(self):
self.db.collection.insert_many(
[{'f1': 'v1', 'k1': 'v1'}, {'f1': 'v2', 'k1': 'v1'},
{'f1': 'v3', 'k1': 'v2'}])
self.assertEqual(set(self.db.collection.distinct('f1', {'k1': 'v1'})), set(['v1', 'v2']))
self.assertEqual(set(self.db.collection.distinct('f1', {'k1': 'v1'})), {'v1', 'v2'})

def test__distinct_error(self):
with self.assertRaises(TypeError):
Expand Down Expand Up @@ -306,7 +306,7 @@ class Document(dict):

def __init__(self, collection):
self.collection = collection
super(Document, self).__init__()
super().__init__()
self.save()

def save(self):
Expand Down Expand Up @@ -1374,7 +1374,7 @@ def test__cursor_distinct(self):
self.db['coll_name'].insert_many([larry_bob, larry, gary])
ret_val = self.db['coll_name'].find().distinct('name')
self.assertIsInstance(ret_val, list)
self.assertTrue(set(ret_val) == set(['larry', 'gary']))
self.assertTrue(set(ret_val) == {'larry', 'gary'})

def test__cursor_limit(self):
self.db.collection.insert_many([{'a': i} for i in range(100)])
Expand Down Expand Up @@ -2486,7 +2486,7 @@ def test__rename_collection(self):

self.assertEqual('collection', coll.name)
self.assertEqual(
set(['other_name']), set(self.db.list_collection_names()))
{'other_name'}, set(self.db.list_collection_names()))
self.assertNotEqual(coll, self.db.other_name)
self.assertEqual([], list(coll.find()))
data_in_db = self.db.other_name.find()
Expand All @@ -2508,7 +2508,7 @@ def test__rename_collection_drop_target(self):
coll = self.db.create_collection('a')
self.db.create_collection('c')
coll.rename('c', dropTarget=True)
self.assertEqual(set(['c']), set(self.db.list_collection_names()))
self.assertEqual({'c'}, set(self.db.list_collection_names()))

def test__cursor_rewind(self):
coll = self.db.create_collection('a')
Expand Down Expand Up @@ -4125,11 +4125,11 @@ def test__aggregate_switch_operation_failures(self):
),
(
{'$switch': {'branches': [{'case': True, 'then': 3}, 7]}},
'$switch expected each branch to be an object, found: %s' % type(0),
'$switch expected each branch to be an object, found: %s' % int,
),
(
{'$switch': {'branches': [7, {}]}},
'$switch expected each branch to be an object, found: %s' % type(0),
'$switch expected each branch to be an object, found: %s' % int,
),
(
{'$switch': {'branches': [{'case': False, 'then': 3}]}},
Expand Down Expand Up @@ -4938,7 +4938,7 @@ def test__array_size_non_array(self):
{'$project': {'size': {'$size': 'arr'}}}
])
self.assertEqual(
'The argument to $size must be an array, but was of type: %s' % type('arr'),
'The argument to $size must be an array, but was of type: %s' % str,
str(err.exception))

def test__array_size_argument_array(self):
Expand Down Expand Up @@ -7167,16 +7167,16 @@ def test_elem_match(self):
{'_id': 1, 'arr': [0, 2, 4, 6]},
{'_id': 2, 'arr': [1, 3, 5, 7]}
])
ids = set(doc['_id'] for doc in self.db.collection.find(
{'arr': {'$elemMatch': {'$lt': 10, '$gt': 4}}}, {'_id': 1}))
ids = {doc['_id'] for doc in self.db.collection.find(
{'arr': {'$elemMatch': {'$lt': 10, '$gt': 4}}}, {'_id': 1})}
self.assertEqual({1, 2}, ids)

def test_list_collection_names_filter(self):
now = datetime.now()
self.db.create_collection('aggregator')
for day in range(10):
new_date = now - timedelta(day)
self.db.create_collection('historical_{0}'.format(new_date.strftime('%Y_%m_%d')))
self.db.create_collection('historical_{}'.format(new_date.strftime('%Y_%m_%d')))

# test without filter
self.assertEqual(len(self.db.list_collection_names()), 11)
Expand All @@ -7187,7 +7187,7 @@ def test_list_collection_names_filter(self):
})) == 10

new_date = datetime.now() - timedelta(1)
col_name = 'historical_{0}'.format(new_date.strftime('%Y_%m_%d'))
col_name = 'historical_{}'.format(new_date.strftime('%Y_%m_%d'))

# test not equal
self.assertEqual(len(self.db.list_collection_names(filter={'name': {'$ne': col_name}})), 10)
Expand Down
Loading
0