diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0d1da4e..eb42137 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -27,11 +27,13 @@ jobs: - name: Install checkers run: | python -mpip install --upgrade pip - python -mpip install black flake8 + python -mpip install black flake8 mypy types-PyYaml - name: flake run: flake8 . - name: black run: black --check --diff --color --quiet . + - name: mypy + run: mypy # REPLACE BY: job which python -mbuild, and uploads the sdist and wheel to artifacts # build is not binary so can just build the one using whatever python version diff --git a/pyproject.toml b/pyproject.toml index b42d432..2be9ead 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -42,3 +42,54 @@ classifiers = [ "Programming Language :: Python :: Implementation :: CPython", "Programming Language :: Python :: Implementation :: PyPy" ] + +[tool.mypy] +python_version = "3.8" +files = "src,tests" + +# can't use strict because it's only global + +# these two are global +warn_unused_configs = true +warn_redundant_casts = true + +# these can be overridden (maybe?) +strict_equality = true +strict_concatenate = true +check_untyped_defs = true +disallow_subclassing_any = true +disallow_untyped_decorators = true +disallow_any_generics = true +disallow_untyped_calls = true +disallow_incomplete_defs = true +disallow_untyped_defs = true +no_implicit_reexport = true +warn_return_any = true + +[[tool.mypy.overrides]] +module = "ua_parser.user_agent_parser" + +#check_untyped_defs = false +disallow_untyped_calls = false +#disallow_incomplete_defs = false +disallow_untyped_defs = false + +[[tool.mypy.overrides]] +module = [ + "test_core", + "test_caches", + "test_parsers_basics", +] + +#check_untyped_defs = false +#disallow_untyped_calls = false +#disallow_incomplete_defs = false +disallow_untyped_defs = false + +[[tool.mypy.overrides]] +module = "test_legacy" + +#check_untyped_defs = false +disallow_untyped_calls = false +#disallow_incomplete_defs = false +disallow_untyped_defs = false diff --git a/src/ua_parser/user_agent_parser.py b/src/ua_parser/user_agent_parser.py index d44133a..7a5ba12 100644 --- a/src/ua_parser/user_agent_parser.py +++ b/src/ua_parser/user_agent_parser.py @@ -181,7 +181,7 @@ def Parse(self, user_agent_string: str) -> Tuple[ _PARSE_CACHE: Dict[str, Dict[str, Any]] = {} -def _lookup(ua: str): +def _lookup(ua): if not isinstance(ua, str): raise TypeError(f"Expected user agent to be a string, got {ua!r}") @@ -204,7 +204,7 @@ def _cached(ua, key, fn): return r -def Parse(user_agent_string: str, **_jsParseBits): +def Parse(user_agent_string, **_jsParseBits): """Parse all the things Args: user_agent_string: the full user agent string diff --git a/tox.ini b/tox.ini index 57b17f9..6dac8a2 100644 --- a/tox.ini +++ b/tox.ini @@ -2,12 +2,12 @@ min_version = 4.0 env_list = py3{8,9,10,11,12} pypy3.{8,9,10} - flake8, black + flake8, black, typecheck labels = test = py3{8,9,10,11,12},pypy3.{8,9,10} cpy = py3{8,9,10,11,12} pypy = pypy3.{8,9,10} - check = flake8, black + check = flake8, black, typecheck [testenv] # wheel install @@ -30,7 +30,14 @@ commands = flake8 {posargs} [testenv:black] package = skip deps = black -commands = black --check --diff . +commands = black --check --diff {posargs:.} + +[testenv:typecheck] +package = skip +deps = + mypy + types-PyYaml +commands = mypy {posargs:} [flake8] max_line_length = 88