Skip to content

Commit 636bee5

Browse files
fix total method on counters, remove deptry
1 parent ed6a5ea commit 636bee5

File tree

5 files changed

+57
-36
lines changed

5 files changed

+57
-36
lines changed

Makefile

-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ check: ## Run code quality tools.
1111
@poetry lock --check
1212
@echo "🚀 Linting code: Running pre-commit"
1313
@poetry run pre-commit run -a
14-
@echo "🚀 Checking for obsolete dependencies: Running deptry"
15-
@poetry run deptry .
1614

1715
.PHONY: test
1816
test: ## Test the code with pytest

json_explorer/explore.py

+16-2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,20 @@ def oxford_join(items, pluralize=False):
2929
return "{}, or {}".format(", ".join(items[:-1]), items[-1])
3030

3131

32+
class Counter(collections.Counter):
33+
"""The 'total' method is only available on a collections.Counter
34+
in python >= 3.10, so add the method to be compatible with earlier
35+
versions.
36+
37+
"""
38+
39+
def total(self):
40+
try:
41+
return super().total()
42+
except AttributeError:
43+
return sum(self.values())
44+
45+
3246
class TripleCounter(dict):
3347
def increment(self, keys, amount):
3448
try:
@@ -40,13 +54,13 @@ def increment(self, keys, amount):
4054
if a not in self:
4155
self[a] = {}
4256
if b not in self[a]:
43-
self[a][b] = collections.Counter()
57+
self[a][b] = Counter()
4458
self[a][b][c] += amount
4559

4660
def tree(self):
4761
result = {}
4862
for a, sub_dict in self.items():
49-
sub_counter = collections.Counter()
63+
sub_counter = Counter()
5064
for b, c_counter in sub_dict.items():
5165
sub_counter[b] += c_counter.total()
5266

poetry.lock

+38-29
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

+1-2
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,11 @@ packages = [
1414
greet = "json_explorer.explore:main"
1515

1616
[tool.poetry.dependencies]
17-
python = ">=3.8,<4.0"
17+
python = ">=3.7,<4.0"
1818

1919
[tool.poetry.group.dev.dependencies]
2020
pytest = "^7.2.0"
2121
pytest-cov = "^4.0.0"
22-
deptry = "^0.6.4"
2322
pre-commit = "^2.20.0"
2423
tox = "^3.25.1"
2524
beautifulsoup4 = "^4.12.2"

tox.ini

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
[tox]
22
skipsdist = true
3-
envlist = py38, py39, py310, py311
3+
envlist = py37, py38, py39, py310, py311
44

55
[gh-actions]
66
python =
7+
3.7: py37
78
3.8: py38
89
3.9: py39
910
3.10: py310

0 commit comments

Comments
 (0)