Skip to content

Commit

Permalink
make mypy happy
Browse files Browse the repository at this point in the history
  • Loading branch information
bfontaine committed Jan 22, 2024
1 parent f63666d commit 16f47d7
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
- name: Lint with Mypy
run: |
poetry run mypy --ignore-missing-imports --warn-return-any wpydumps
poetry run mypy --check-untyped-defs wpydumps
- name: Unit tests
run: |
Expand Down
7 changes: 7 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,10 @@ mypy = "^1.8.0"
[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

[[tool.mypy.overrides]]
module = [
"libarchive",
"libarchive.public",
]
ignore_missing_imports = true
4 changes: 1 addition & 3 deletions wpydumps/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# -*- coding: UTF-8 -*-

__version__ = "0.2.0"
__version__ = "0.3.0"

from wpydumps.parser import parse_pages_from_reader, parse_pages_from_archive_filename
2 changes: 0 additions & 2 deletions wpydumps/archive.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# -*- coding: UTF-8 -*-

import io
from typing import Iterable

Expand Down
1 change: 0 additions & 1 deletion wpydumps/model.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: UTF-8 -*-
from typing import Optional, List


Expand Down
25 changes: 20 additions & 5 deletions wpydumps/parser.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# -*- coding: UTF-8 -*-

from collections import deque
from typing import Callable, Optional, Any, Deque, cast, List
from typing import Callable, Optional, Any, Deque, List
from xml import sax

from wpydumps.model import Page, Revision, Contributor
Expand All @@ -10,6 +8,7 @@
PageCallbackType = Callable[[Page], Any]


# noinspection PyPep8Naming
class PageHandler(sax.handler.ContentHandler):
"""
SAX handler to parse page revisions from a Wikipedia dump.
Expand Down Expand Up @@ -61,6 +60,8 @@ def startElement(self, name, attrs):

parent = self.parentElement()
if parent == "page":
assert self._current_page is not None

if name == "redirect":
self._current_page.redirect = attrs["title"]
return
Expand All @@ -69,6 +70,8 @@ def startElement(self, name, attrs):
return

if parent == "revision":
assert self._current_revision is not None

if name == "minor":
self._current_revision.minor = True
return
Expand Down Expand Up @@ -98,15 +101,21 @@ def endElement(self, name):
self._current_content_fragments = []

if name == "page":
assert self._current_page is not None

self.page_callback(self._current_page)
self._current_page = None
return

if name == "revision":
revision = self._current_revision
assert revision is not None
assert self._current_page is not None

if revision.text_length is None:
revision.text_length = 0

assert self._previous_revision_text_length is not None
revision.diff_length = revision.text_length - self._previous_revision_text_length
self._previous_revision_text_length = revision.text_length

Expand All @@ -119,6 +128,8 @@ def endElement(self, name):
return

if name == "contributor":
assert self._current_revision is not None

self._current_revision.contributor = self._current_contributor
self._current_contributor = None
return
Expand All @@ -132,7 +143,8 @@ def endElement(self, name):
content = content.strip()

if parent == "page":
page = cast(Page, self._current_page)
page = self._current_page
assert page is not None

if element == "ns":
page.namespace = content
Expand All @@ -146,6 +158,8 @@ def endElement(self, name):
return

if parent == "revision":
assert revision is not None

if element == "text":
if self._keep_revisions_text:
revision.text = original_content
Expand All @@ -169,7 +183,8 @@ def endElement(self, name):
return

if parent == "contributor":
contributor = cast(Contributor, self._current_contributor)
contributor = self._current_contributor
assert contributor is not None

if element == "id":
contributor.id = content
Expand Down

0 comments on commit 16f47d7

Please sign in to comment.