Skip to content
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

feat: Add type hints #334

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft

feat: Add type hints #334

wants to merge 2 commits into from

Conversation

taion
Copy link
Contributor

@taion taion commented Apr 30, 2020

No description provided.

@taion taion requested a review from sloria April 30, 2020 17:45
@taion taion marked this pull request as draft April 30, 2020 17:45
@taion
Copy link
Contributor Author

taion commented Apr 30, 2020

@sloria took a stab at starting here... not sure how to even do all the typing here w/sqlalchemy, though

Copy link
Member

@sloria sloria left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good on first glance. Will you be adding mypy?

@taion
Copy link
Contributor Author

taion commented Apr 30, 2020

probably not going to add mypy any time soon

@sloria
Copy link
Member

sloria commented Apr 30, 2020

Here's a run with the mypy defaults

diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index 3d8d20d..8461356 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -8,6 +8,10 @@ repos:
   rev: v0.4.3
   hooks:
     - id: fourmat
+- repo: https://github.com/pre-commit/mirrors-mypy
+  rev: v0.770
+  hooks:
+  - id: mypy
 - repo: https://github.com/asottile/blacken-docs
   rev: v1.6.0
   hooks:
flask-resty ❯ tox -e lint
lint installed: appdirs==1.4.3,cfgv==3.1.0,distlib==0.3.0,filelock==3.0.12,Flask-RESTy==1.1.0,identify==1.4.15,nodeenv==1.3.5,pre-commit==2.3.0,PyYAML==5.3.1,six==1.14.0,toml==0.10.0,virtualenv==20.0.18
lint run-test-pre: PYTHONHASHSEED='1457359984'
lint run-test: commands[0] | pre-commit run --all-files
pyupgrade................................................................Passed
fourmat..................................................................Passed
mypy.....................................................................Failed
- hook id: mypy
- exit code: 1

flask_resty/routing.py:4: error: Module 'werkzeug.routing' has no attribute 'RequestPath'; maybe "RequestSlash"?
flask_resty/context.py:1: error: Module 'flask' has no attribute '_request_ctx_stack'
flask_resty/view.py:63: error: Incompatible types in assignment (expression has type "NoOpAuthentication", variable has type "AuthenticationBase")
flask_resty/view.py:374: error: Need type annotation for 'id'
flask_resty/view.py:392: error: Incompatible return value type (got "Tuple[Any, ...]", expected "_TId")
flask_resty/view.py:408: error: Item "None" of "Optional[Any]" has no attribute "fields"
flask_resty/view.py:441: error: Item "None" of "Optional[Any]" has no attribute "load"
flask_resty/view.py:493: error: Incompatible types in assignment (expression has type "Tuple[_TId]", variable has type "_TId")
flask_resty/view.py:495: error: No overload variant of "zip" matches argument types "Sequence[str]", "_TId"
flask_resty/view.py:495: note: Possible overload variant:
flask_resty/view.py:495: note:     def [_T1, _T2] zip(Iterable[_T1], Iterable[_T2]) -> Iterator[Tuple[_T1, _T2]]
flask_resty/view.py:495: note:     <5 more non-matching overloads not shown>
flask_resty/view.py:515: error: Incompatible types in assignment (expression has type "None", variable has type "Type[TItem]")
flask_resty/view.py:540: error: "Type[TItem]" has no attribute "query"
flask_resty/view.py:722: error: Need type annotation for 'data'
flask_resty/view.py:733: error: Incompatible return value type (got "Dict[Any, Any]", expected "_TDataIn")
flask_resty/view.py:747: error: Need type annotation for 'id'
flask_resty/view.py:812: error: Too many arguments for "object"
flask_resty/view.py:1083: error: Need type annotation for 'data_in'
flask_resty/view.py:1111: error: Need type annotation for 'data_in'
flask_resty/view.py:1130: error: Need type annotation for 'data_in'
flask_resty/api.py:161: error: "ApiView[Any]" has no attribute "__name__"
flask_resty/api.py:165: error: "ApiView[Any]" has no attribute "__name__"
example/views.py:22: error: Incompatible types in assignment (expression has type "NoOpAuthentication", base class "ApiView" defined the type as "AuthenticationBase")
example/views.py:52: error: Incompatible types in assignment (expression has type "NoOpAuthentication", base class "ApiView" defined the type as "AuthenticationBase")
example/routes.py:9: error: Argument 2 to "add_resource" of "Api" has incompatible type "Type[AuthorListView]"; expected "ApiView[Any]"
example/routes.py:9: error: Argument 3 to "add_resource" of "Api" has incompatible type "Type[AuthorView]"; expected "Optional[ApiView[Any]]"
example/routes.py:10: error: Argument 2 to "add_resource" of "Api" has incompatible type "Type[BookListView]"; expected "ApiView[Any]"
example/routes.py:10: error: Argument 3 to "add_resource" of "Api" has incompatible type "Type[BookView]"; expected "Optional[ApiView[Any]]"
example/models.py:12: error: Name 'db.Model' is not defined
example/models.py:22: error: Name 'db.Model' is not defined
Found 28 errors in 7 files (checked 46 source files)

blacken-docs.............................................................Passed
ERROR: InvocationError for command /Users/sloria/projects/4Catalyzer/flask-resty/.tox/lint/bin/pre-commit run --all-files (exited with code 1)
_________________________________________________________________________________________________________________________________________________________________________________ summary __________________________________________________________________________________________________________________________________________________________________________________
ERROR:   lint: commands failed

from .utils import settable_property

# -----------------------------------------------------------------------------

TItem = TypeVar("TItem")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

geez generics are so terrible...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants