Skip to content

Commit

Permalink
Add typechecker
Browse files Browse the repository at this point in the history
Remove partial typing on the legacy API whose only effect is to break
typechecking.

Fixes #179
  • Loading branch information
masklinn committed Feb 6, 2024
1 parent 69087a7 commit b408a13
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 6 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
51 changes: 51 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions src/ua_parser/user_agent_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}")

Expand All @@ -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
Expand Down
13 changes: 10 additions & 3 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit b408a13

Please sign in to comment.