From 06b08b30faa00237df85327036d3ec18b778a277 Mon Sep 17 00:00:00 2001 From: Ben Kurtovic Date: Sun, 25 Aug 2024 23:55:01 -0400 Subject: [PATCH] Add pyright pre-commit hook --- .pre-commit-config.yaml | 4 ++++ LICENSE | 2 +- pyproject.toml | 14 ++++++++++++++ src/earwigbot/wiki/copyvios/result.py | 17 +++++++---------- 4 files changed, 26 insertions(+), 11 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 223f906..548c3b6 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -5,3 +5,7 @@ repos: - id: ruff args: [--fix] - id: ruff-format + - repo: https://github.com/RobertCraigie/pyright-python + rev: v1.1.377 + hooks: + - id: pyright diff --git a/LICENSE b/LICENSE index b567c42..4d81c9e 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (C) 2009-2017 Ben Kurtovic +Copyright (C) 2009-2024 Ben Kurtovic Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/pyproject.toml b/pyproject.toml index 28cb780..384e3a1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -58,6 +58,20 @@ earwigbot = "earwigbot.cli:main" requires = ["setuptools>=61.0"] build-backend = "setuptools.build_meta" +[tool.pyright] +exclude = [ + # TODO + "src/earwigbot/commands", + "src/earwigbot/config", + "src/earwigbot/lazy.py", + "src/earwigbot/irc", + "src/earwigbot/tasks", + "src/earwigbot/wiki/copyvios" +] +pythonVersion = "3.11" +venvPath = "." +venv = "venv" + [tool.ruff] target-version = "py311" diff --git a/src/earwigbot/wiki/copyvios/result.py b/src/earwigbot/wiki/copyvios/result.py index fb6624f..937bad3 100644 --- a/src/earwigbot/wiki/copyvios/result.py +++ b/src/earwigbot/wiki/copyvios/result.py @@ -18,11 +18,10 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. +import urllib.parse from threading import Event from time import time -import urlparse - from earwigbot.wiki.copyvios.markov import EMPTY, EMPTY_INTERSECTION __all__ = ["CopyvioSource", "CopyvioCheckResult"] @@ -89,7 +88,7 @@ class CopyvioSource: @property def domain(self): """The source URL's domain name, or None.""" - return urlparse.urlparse(self.url).netloc or None + return urllib.parse.urlparse(self.url).netloc or None def start_work(self): """Mark this source as being worked on right now.""" @@ -182,13 +181,11 @@ class CopyvioCheckResult: @property def confidence(self): """The confidence of the best source, or 0 if no sources exist.""" - return ( - self.unified_confidence - if self.unified_confidence is not None - else self.best.confidence - if self.best - else 0.0 - ) + if self.unified_confidence is not None: + return self.unified_confidence + if self.best: + return self.best.confidence + return 0.0 @property def url(self):