-
Notifications
You must be signed in to change notification settings - Fork 289
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] Stricter checks mypy #240
[ADD] Stricter checks mypy #240
Conversation
e8cb0ba
to
2fbe1c6
Compare
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.
Thanks for the PR, I will put some good practices for mypy typing:
-
class rather than
Dict[str, Any]
BecauseDict[str, Any]
is not supported by most languages, because of lower safety. -
sometimes it is effective to declare typing variables as a global variable to comprehend inputs as a same group.
For python3.8 >=,
-
Generic class
We can use something liketemplate
in C++
We can separateUnion
depending on files. -
Literal
we can accept only specific variable rather than typing -
Final
If we do not hope the change in variables, we can use it. -
TypedDict
We can define meta class for dict.
Also we need to discuss (with Frank as well) when we should stop the support of older python versions.
Just in case, python3.6 is already not supported officially and python3.7 will be not supported from this December.
1f216a8
to
c107ee8
Compare
Codecov Report
@@ Coverage Diff @@
## development #240 +/- ##
===============================================
+ Coverage 80.82% 81.62% +0.79%
===============================================
Files 148 150 +2
Lines 8563 8625 +62
Branches 1323 1325 +2
===============================================
+ Hits 6921 7040 +119
+ Misses 1163 1108 -55
+ Partials 479 477 -2
Continue to review full report at Codecov.
|
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.
Thanks for the PR. I left some questions. Let me know what you think about them.
@@ -194,8 +194,8 @@ def _check_data( | |||
A set of features whose dimensionality and data type is going to be checked | |||
""" | |||
|
|||
if not isinstance(y, (np.ndarray, pd.DataFrame, typing.List, pd.Series)) and not \ | |||
scipy.sparse.issparse(y): # type: ignore[misc] | |||
if not isinstance(y, (np.ndarray, pd.DataFrame, # type: ignore[misc] |
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.
You can declare a temporal variable for the types.
Anyways, the variable scope here is small enough and it will increase the readability.
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.
So, we already have a variable for the types called SUPPORTED_TARGET_TYPE
which we can use directly using isinstance
checks, however, to check for sparsity we do not use isinstance
rather we use scipy.issparse and hence I did not think it was appropriate to make another variable just for this type check.
15064f5
to
f800b95
Compare
This PR partially addresses #230.