New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fill missing type hints #241
Conversation
@agronholm |
I haven't added the pre-commit configuration to this project yet. |
Why have you added all sorts of unrelated configuration? |
Sorry, removed. |
You should broaden the annotations, possibly using |
There are code styling changes not related to annotations. Please undo those changes. The GitHub Actions workflow should have a step to run mypy. You should add that. |
@agronholm done. |
$ git rev-parse HEAD # now
e84ca55ff3d2743a0924e08ad088f7470f3a4745
$ mypy tests/mypy/test_type_annotations.py src
src/typeguard/__init__.py:1030: error: Argument 3 to "getattr" has incompatible
type "Tuple[]"; expected "bool"
...ty_func is not None and getattr(property_func, '__annotations__', ()):
^
src/typeguard/__init__.py:1033: error: Argument 1 to "property" has
incompatible type "**Dict[str, Optional[str]]"; expected
"Optional[Callable[[Any], Any]]"
setattr(func, key, attr.__class__(**kwargs))
^
src/typeguard/__init__.py:1033: error: Argument 1 to "property" has
incompatible type "**Dict[str, Optional[str]]"; expected
"Optional[Callable[[Any, Any], None]]"
setattr(func, key, attr.__class__(**kwargs))
^
src/typeguard/__init__.py:1033: error: Argument 1 to "property" has
incompatible type "**Dict[str, Optional[str]]"; expected
"Optional[Callable[[Any], None]]"
setattr(func, key, attr.__class__(**kwargs))
^
src/typeguard/__init__.py:1057: error: "None" not callable
retval = func(*args, **kwargs)
^
src/typeguard/__init__.py:1073: error: Returning Any from function declared to
return
"Union[TypeCheckedGenerator, TypeCheckedAsyncGenerator, GeneratorType[Any, Any, Any]]"
return retval
^
src/typeguard/__init__.py:1078: error: "None" not callable
retval = await func(*args, **kwargs)
^
Found 7 errors in 1 file (checked 4 source files) |
This line runs mypy; it should be modified to check the entire codebase. |
Those mypy errors look nonsensical. I wonder if pyright gives similar errors. |
error: Argument 3 to "getattr" has incompatible type "Tuple[]"; expected "bool"
src/typeguard/__init__.py:1033: error: Argument 1 to "property" has incompatible type "**Dict[str, Optional[str]]"; expected "Optional[Callable[[Any], Any]]" setattr(func, key, attr.__class__(**kwargs)) ^ src/typeguard/__init__.py:1033: error: Argument 1 to "property" has incompatible type "**Dict[str, Optional[str]]"; expected "Optional[Callable[[Any, Any], None]]" setattr(func, key, attr.__class__(**kwargs)) ^ src/typeguard/__init__.py:1033: error: Argument 1 to "property" has incompatible type "**Dict[str, Optional[str]]"; expected "Optional[Callable[[Any], None]]" setattr(func, key, attr.__class__(**kwargs)) ^ src/typeguard/__init__.py:1057: error: "None" not callable retval = func(*args, **kwargs) ^ src/typeguard/__init__.py:1073: error: Returning Any from function declared to return "Union[TypeCheckedGenerator, TypeCheckedAsyncGenerator, GeneratorType[Any, Any, Any]]" return retval ^ src/typeguard/__init__.py:1078: error: "None" not callable retval = await func(*args, **kwargs)
$ git rev-parse HEAD # now
a9c2fb9c91303e3d75bb121aeba2ae1655e07b99
$ mypy tests/mypy/test_type_annotations.py src
Success: no issues found in 4 source files
$ pytest
============================= test session starts ==============================
platform darwin -- Python 3.9.9, pytest-6.2.5, py-1.11.0, pluggy-1.0.0
rootdir: /Users/eggplants/prog/typeguard, configfile: pyproject.toml, testpaths: tests
plugins: subtests-0.5.0, monkeytype-1.1.0, mock-3.7.0, typeguard-2.13.3, cov-3.0.0
collected 243 items
tests/test_importhook.py ................. [ 6%]
tests/test_typeguard.py ................................................ [ 26%]
........................................................................ [ 56%]
........................................................................ [ 86%]
................ [ 92%]
tests/test_typeguard_py36.py ................ [ 99%]
tests/mypy/test_type_annotations.py .. [100%]
=============================== warnings summary ===============================
tests/test_typeguard_py36.py::TestTypeChecker::test_callable
/Users/eggplants/.pyenv/versions/3.9.9/lib/python3.9/site-packages/typeguard/__init__.py:1027: UserWarning: no code associated -- not typechecking test_typeguard_py36.<test_typeguard_py36.TestTypeChecker.test_callable.<locals>.command object at 0x111d40130>
warn('no code associated -- not typechecking {}'.format(function_name(func)))
-- Docs: https://docs.pytest.org/en/stable/warnings.html
======================== 243 passed, 1 warning in 1.20s ========================
$ grep -r '# type: ignore' src/typeguard/*.py | wc -l
20 20 suppressed errors exist... |
src/typeguard/__init__.py:1135:30: E126 continuation line over-indented for hanging indent
I'm sorry I didn't think of this before (I was travelling), but you probably should've based this on the 3.0 branch. I have no intention of updating the 2.x series anymore. |
I have not noticed branch |
Please document in either README or Documentation in your free time. |
I expected to release 3.0 much sooner but got sidetracked by other work, leading to this awkward situation. |
To avoid confusion for others, till 3.0 is published, I recommend either:
Otherwise, more people's time is bound to be wasted. |
Closes: #240
typeguard.typechecking
is too complex to annotate correctly. So please tell me your advice, or annotate it instead of me.