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
Add (some) missing type hints for _IssueFields
#1063
Add (some) missing type hints for _IssueFields
#1063
Conversation
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.
Great PR.
I imagine this will also be a pain for basically every customfield property too.
Two options I'm thinking:
- Use an
Any
typehintself.fields: Any
, removing_IssueFields
- Inherit
Any
in the_IssueFields
class during type checking
The inherit Any
is a bit hacky, so perhaps we will just use Any
in the future, but:
if TYPE_CHECKING:
from jira.client import JIRA
MyAny = Any
else:
class MyAny(object):
pass
Then:
class _IssueFields(MyAny):
Otherwise the fields you've added seem fine, some of them I can't see on my instance, or the https://jira.atlassian.com instance, but you've set them as optional so don't think it'll hurt to keep them in.
@studioj any thoughts ?
Thanks @adehad for the feedback. Regarding the customfields, the types I've defined have been made under the assumption that they'd be common for any Jira instance (of course my assumptions may be wrong, and the Jira documentation doesn't really help much for this, at least for what I could find), and that, if someone was looking for some custom fields, they would have to check that the variable is bound. But if subclassing |
Great, let's wait a little bit in case anyone else has any thoughts on the matter. If I was being picky I would suggest doing the |
That makes sense, let's wait for other opinions
No issue, I can do it in this PR already! I'll push the changes in a while |
tbh I'm not that acquainted w type hints. :-) I only recently finally made the step to drop legacy python in my professional life. i'm thinking that it looks rather complicated... is this worth the complexity and added maintenance? (not the PR but the above proposal) |
@ssbarnea any thoughts on the maintenance of these typehints? Least maintenance would be The |
@adehad I've added the types for the |
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.
@julenpardo, great! Although I noticed it looks like you have missed 3 instances at the bottom of the file for: Customer
, ServiceDesk
, RequestType
c487d30
to
c6ec6e6
Compare
@adehad Thanks for the catch! Already added, also for |
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.
Nice, looks good. Now just waiting for a decision on the Any
situation from @ssbarnea
Changes now made, no explicit approval as awaiting decision on Any
typehint
Hey folks, any follow up regarding defining types as |
I do not have time to look into full details of this but use of Any is almost always a type problem. |
Hi @julenpardo let's implement the |
I'm not strong opinionated about this. As of me, having no types at all (specially when just some of them were added) would still be fine. I can understand that the argument in favor of I originally opened this PR with the intention solely of unbreaking the type checker, so any decision taken here would be okay from my side. |
Thanks @adehad, I posted the previous comment just before seeing yours :) I'll make the changes and ping you back |
@adehad I've made |
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.
@julenpardo let me get back to you on the existing typehints, I think we may be able to just leave them in. For now could you merge in the latest master to make sure the pipeline is remains all good?
@ssbarnea regarding the Any
type hint - agree, we are basing the json fields on a Dict[str,Any]
- which is what we need to rely on until we get recursive type support in mypy: python/typing#182 (comment) and python/mypy#731. We have to fallback to Any
here because we support accessing the json dict fields with __getattr__
, so it gets a bit funky, for example if there is a custom field we haven't type hinted
2331f7c
to
3a511b8
Compare
@adehad Thanks for following up with this, already rebased latest master and addressed the comment |
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.
@adehad I personally found |
* Add missing type hints * Add type for _raw after parsing * Define type for raw for every resource * Subclass `Any` for _IssueFields when running type checking * Nitpick ignore MyAny
Description
Tested with mypy 0.782.
Pull request #1023 added some type hints, which is great, but didn't define all of them, which now makes mypy unhappy about it.
Note: this PR probably doesn't add all of them either, but it does add some of them that do exist (most notably, fields like
summary
orcreated
). I haven't found in the Jira REST API documentation a specific list of the fields that have a required value, so the types added by this PR are based in the errors of our codebase, intuition and requests examples provided by Jira docs. I'd be happy to add more fields if necessary.Rationale
Because mypy assumes the type
Any
for when there's no type hint, the solution should be to either to define every class attribute with its type, or define no types at all. This design by mypy is intentional for backwards compatibility (among other reasons). Having partially defined types can only break existing set ups.Minimal reproducible example