Skip to content

Commit b408a13

Browse files
committed
Add typechecker
Remove partial typing on the legacy API whose only effect is to break typechecking. Fixes #179
1 parent 69087a7 commit b408a13

4 files changed

Lines changed: 66 additions & 6 deletions

File tree

.github/workflows/ci.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,13 @@ jobs:
2727
- name: Install checkers
2828
run: |
2929
python -mpip install --upgrade pip
30-
python -mpip install black flake8
30+
python -mpip install black flake8 mypy types-PyYaml
3131
- name: flake
3232
run: flake8 .
3333
- name: black
3434
run: black --check --diff --color --quiet .
35+
- name: mypy
36+
run: mypy
3537

3638
# REPLACE BY: job which python -mbuild, and uploads the sdist and wheel to artifacts
3739
# build is not binary so can just build the one using whatever python version

pyproject.toml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,54 @@ classifiers = [
4242
"Programming Language :: Python :: Implementation :: CPython",
4343
"Programming Language :: Python :: Implementation :: PyPy"
4444
]
45+
46+
[tool.mypy]
47+
python_version = "3.8"
48+
files = "src,tests"
49+
50+
# can't use strict because it's only global
51+
52+
# these two are global
53+
warn_unused_configs = true
54+
warn_redundant_casts = true
55+
56+
# these can be overridden (maybe?)
57+
strict_equality = true
58+
strict_concatenate = true
59+
check_untyped_defs = true
60+
disallow_subclassing_any = true
61+
disallow_untyped_decorators = true
62+
disallow_any_generics = true
63+
disallow_untyped_calls = true
64+
disallow_incomplete_defs = true
65+
disallow_untyped_defs = true
66+
no_implicit_reexport = true
67+
warn_return_any = true
68+
69+
[[tool.mypy.overrides]]
70+
module = "ua_parser.user_agent_parser"
71+
72+
#check_untyped_defs = false
73+
disallow_untyped_calls = false
74+
#disallow_incomplete_defs = false
75+
disallow_untyped_defs = false
76+
77+
[[tool.mypy.overrides]]
78+
module = [
79+
"test_core",
80+
"test_caches",
81+
"test_parsers_basics",
82+
]
83+
84+
#check_untyped_defs = false
85+
#disallow_untyped_calls = false
86+
#disallow_incomplete_defs = false
87+
disallow_untyped_defs = false
88+
89+
[[tool.mypy.overrides]]
90+
module = "test_legacy"
91+
92+
#check_untyped_defs = false
93+
disallow_untyped_calls = false
94+
#disallow_incomplete_defs = false
95+
disallow_untyped_defs = false

src/ua_parser/user_agent_parser.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ def Parse(self, user_agent_string: str) -> Tuple[
181181
_PARSE_CACHE: Dict[str, Dict[str, Any]] = {}
182182

183183

184-
def _lookup(ua: str):
184+
def _lookup(ua):
185185
if not isinstance(ua, str):
186186
raise TypeError(f"Expected user agent to be a string, got {ua!r}")
187187

@@ -204,7 +204,7 @@ def _cached(ua, key, fn):
204204
return r
205205

206206

207-
def Parse(user_agent_string: str, **_jsParseBits):
207+
def Parse(user_agent_string, **_jsParseBits):
208208
"""Parse all the things
209209
Args:
210210
user_agent_string: the full user agent string

tox.ini

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
min_version = 4.0
33
env_list = py3{8,9,10,11,12}
44
pypy3.{8,9,10}
5-
flake8, black
5+
flake8, black, typecheck
66
labels =
77
test = py3{8,9,10,11,12},pypy3.{8,9,10}
88
cpy = py3{8,9,10,11,12}
99
pypy = pypy3.{8,9,10}
10-
check = flake8, black
10+
check = flake8, black, typecheck
1111

1212
[testenv]
1313
# wheel install
@@ -30,7 +30,14 @@ commands = flake8 {posargs}
3030
[testenv:black]
3131
package = skip
3232
deps = black
33-
commands = black --check --diff .
33+
commands = black --check --diff {posargs:.}
34+
35+
[testenv:typecheck]
36+
package = skip
37+
deps =
38+
mypy
39+
types-PyYaml
40+
commands = mypy {posargs:}
3441

3542
[flake8]
3643
max_line_length = 88

0 commit comments

Comments
 (0)