From 91401a2d3390d4583b3bcf8bdbd3a0449a0e8ebb Mon Sep 17 00:00:00 2001 From: Nathan Henrie Date: Fri, 29 Dec 2023 15:45:33 -0700 Subject: [PATCH] mypy fixes --- src/pycookiecheat/chrome.py | 5 ++--- src/pycookiecheat/common.py | 10 +++++++--- tests/test_chrome.py | 2 +- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/pycookiecheat/chrome.py b/src/pycookiecheat/chrome.py index 77a6afe..2ee1e8c 100644 --- a/src/pycookiecheat/chrome.py +++ b/src/pycookiecheat/chrome.py @@ -260,10 +260,9 @@ def chrome_cookies( {"init_vector": b" " * 16, "length": 16, "salt": b"saltysalt"} ) - if cookie_file is not None: - cookie_file = Path(cookie_file) - else: + if cookie_file is None: cookie_file = config["cookie_file"] + cookie_file = Path(cookie_file) if isinstance(password, bytes): config["my_pass"] = password diff --git a/src/pycookiecheat/common.py b/src/pycookiecheat/common.py index a86394a..b4ff290 100644 --- a/src/pycookiecheat/common.py +++ b/src/pycookiecheat/common.py @@ -1,6 +1,8 @@ """Common code for pycookiecheat.""" +from __future__ import annotations + from dataclasses import dataclass -from enum import Enum +from enum import Enum, unique from typing import Iterator from warnings import warn @@ -61,7 +63,7 @@ def generate_host_keys(hostname: str) -> Iterator[str]: yield "." + domain -def deprecation_warning(msg: str): +def deprecation_warning(msg: str) -> None: """Raise a deprecation warning with the provided message. `stacklevel=3` tries to show the appropriate calling code to the user. @@ -69,6 +71,7 @@ def deprecation_warning(msg: str): warn(msg, DeprecationWarning, stacklevel=3) +@unique class BrowserType(str, Enum): """Provide discrete values for recognized browsers. @@ -89,8 +92,9 @@ class BrowserType(str, Enum): FIREFOX = "firefox" SLACK = "slack" + # https://mypy.readthedocs.io/en/stable/common_issues.html#incompatible-overrides @classmethod - def _missing_(cls, value: str): + def _missing_(cls, value: str) -> BrowserType: # type: ignore[override] """Provide case-insensitive matching for input values. >>> BrowserType("chrome") diff --git a/tests/test_chrome.py b/tests/test_chrome.py index ef484cd..b270c63 100755 --- a/tests/test_chrome.py +++ b/tests/test_chrome.py @@ -52,7 +52,7 @@ def ci_setup() -> t.Generator: ignore_default_args=[ "--use-mock-keychain", ], - executable_path=ex_path, # type: ignore + executable_path=ex_path, ) page = browser.new_page() page.goto("https://n8henrie.com")