-
Notifications
You must be signed in to change notification settings - Fork 12
Type hints #22
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
Type hints #22
Conversation
# Conflicts: # README.md # connect/resource/base.py # example/example.py # tests/test_config.py
# Conflicts: # connect/models/asset.py # connect/models/fulfillment.py
Codecov Report
@@ Coverage Diff @@
## master #22 +/- ##
==========================================
+ Coverage 84.25% 86.88% +2.63%
==========================================
Files 24 24
Lines 527 633 +106
==========================================
+ Hits 444 550 +106
Misses 83 83
Continue to review full report at Codecov.
|
connect/config.py
Outdated
| products=None, | ||
| file=None | ||
| ): | ||
| # type: (str, str, Union[str, List[str]], str) -> None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably, better to use alternate syntax for multi-parameter functions, where hint comment placed right after parameter?
api_url=None, # type: str
api_key=None, # type: str
...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you feel that's more readable, I'll change it, the version you propose is perfectly fine and PyCharm understands it. I just used the other one because that's how PyCharm autogenerates the hints when you select 'Add type hints for function'.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed.
connect/resource/template.py
Outdated
| return ActivationTemplateResponse(template_id=pk) | ||
|
|
||
| def list(self): | ||
| # type: () -> Any |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
more or less pointless type-hinting (there and in similar places)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True. I'll check those and fix them. This one should probably be # type: () -> List[BaseModel] on BaseResource, and a list of specific BaseModel subclasses on derived resources.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
connect/resource/base.py
Outdated
|
|
||
| @property | ||
| def headers(self): | ||
| # type: () -> dict |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not
type: () -> Dict[str, str]
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know why :) I'll fix this one and check similar ones.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
connect/resource/fulfillment.py
Outdated
|
|
||
| @function_log | ||
| def update_parameters(self, pk, params): | ||
| # type: (str, list) -> str |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(str, List[Param]) -> str ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, better like that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
…d out on FulfillmentAutomation.process!)
Added type hints in a Python 2 compatible way (by putting the types in comments following member var and method declarations).
This allows PyCharm's Code Inspect tool to capture access to invalid attributes, and vastly improves intellisense, by providing suggestions of available attributes when using the dot operator on a model.