Skip to content
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

Add recommended mypy settings #117

Merged
merged 2 commits into from
Dec 24, 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
72 changes: 45 additions & 27 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"


# poetry
# ------

[tool.poetry]
name = "listparser"
version = "0.20"
Expand All @@ -14,24 +22,19 @@ classifiers = [
"Topic :: Text Processing :: Markup :: XML",
]


[tool.poetry.dependencies]
python = ">=3.9"
# The dependencies here must match the minimums tested in `tox.ini`.
requests = {version = ">=2.32.0,<3", optional = true}
lxml = {version = ">=4.6.2,<6", optional = true}


[tool.poetry.extras]
http = ["requests"]
lxml = ["lxml"]


[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"


# coverage
# --------

[tool.coverage.run]
relative_files = true
Expand All @@ -42,24 +45,56 @@ source = [
"tests",
]


[tool.coverage.paths]
source = [
"src",
"*/site-packages",
]


[tool.coverage.report]
skip_covered = true
fail_under = 100


[tool.coverage.html]
directory = "htmlcov/"
skip_covered = false


# isort
# -----

[tool.isort]
profile = "black"


# mypy
# ----

[tool.mypy]
packages = "listparser"
strict = true
sqlite_cache = true
warn_unreachable = true
enable_error_code = [
"ignore-without-code",
"redundant-expr",
"truthy-bool",
]


# pytest
# ------

[tool.pytest.ini_options]
addopts = "--color=yes"
filterwarnings = [
"error",
]


# scriv
# -----

[tool.scriv]
version = "literal: pyproject.toml: tool.poetry.version"
categories = [
Expand All @@ -78,20 +113,3 @@ fragment_directory = "changelog.d"
insert_marker = "scriv-insert-here"
main_branches = ["main", "releases"]
new_fragment_template = "file: fragment-template.rst.txt"


[tool.isort]
profile = "black"


[tool.mypy]
packages = "listparser"
strict = true
sqlite_cache = true


[tool.pytest.ini_options]
addopts = "--color=yes"
filterwarnings = [
"error",
]
10 changes: 7 additions & 3 deletions src/listparser/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def parse(parse_obj: str | bytes) -> common.SuperDict:
parser = lxml.etree.HTMLParser(target=handler, recover=True)
lxml.etree.parse(content_file, parser)
else:
handler.feed(content.decode())
handler.feed(content.decode()) # type: ignore[unreachable]

harvest = common.SuperDict(handler.harvest)
handler.close()
Expand All @@ -87,7 +87,9 @@ def get_content(obj: bytes | str) -> tuple[bytes | None, dict[str, t.Any]]:
return obj, {"bozo": False, "bozo_exception": None}
if not isinstance(obj, str):
# Only str and bytes objects can be parsed.
error = ListparserError("parse() called with unparsable object")
message = "parse() called with unparsable object" # type: ignore[unreachable]
error = ListparserError(message)

return None, {"bozo": True, "bozo_exception": error}
if not obj.startswith(("http://", "https://")):
# It's not a URL, so it must be treated as an XML document.
Expand All @@ -98,7 +100,9 @@ def get_content(obj: bytes | str) -> tuple[bytes | None, dict[str, t.Any]]:

# It's a URL. Confirm requests is installed.
if requests is None:
message = f"requests is not installed so {obj} cannot be retrieved"
message = ( # type: ignore[unreachable]
f"requests is not installed so {obj} cannot be retrieved"
)
return None, {
"bozo": True,
"bozo_exception": ListparserError(message),
Expand Down
Loading