-
Notifications
You must be signed in to change notification settings - Fork 10
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
Fully type-annotate and type-check everything #100
Conversation
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## master #100 +/- ##
==========================================
+ Coverage 96.67% 97.71% +1.04%
==========================================
Files 18 17 -1
Lines 1654 1751 +97
==========================================
+ Hits 1599 1711 +112
+ Misses 55 40 -15
Flags with carried forward coverage won't be shown. Click here to find out more.
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View 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.
some comments. i'll address your comments in a separate thread.
@@ -134,7 +134,7 @@ def to_datacite( | |||
NAME_PATTERN, contr_el.name | |||
).pop() | |||
|
|||
if getattr(contr_el, "affiliation"): | |||
if hasattr(contr_el, "affiliation") and contr_el.affiliation is not 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.
can this not be replaced by the following pattern?
if hasattr(contr_el, "affiliation") and contr_el.affiliation is not None: | |
if getattr(contr_el, "affiliation", 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.
If using getattr
, mypy can't tell whether contr_el.affiliation
is None
or not, so it'll warn when it's used in a non-None
way inside the block.
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.
that sounds like a deficiency in mypy
since logically it cannot be None
since then if
would not evaluate to True. Do you know of the issue may be already in mypy on this?
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.
python/mypy#11142 seems like a good starting point.
mypy doesn't tend to like anything dynamic. if you have a suggestion let me know. we need more info around those enums, so turning them into enums to start with will lose that capability.
this was added by @yarikoptic instead of manually writing schemaKey in every class. in terms of functionality i believe it works, can you suggested why you think it doesn't work?
a
pydantic doesn't allow regex's for url patterns. and we need to be more specific as to what that published url looks like. this is why it was changed to a
i don't have a good suggestion, but we will likely continue with dynamic configurations. |
Need more info for what? In the current state, I don't see what is gained from the dynamic construction.
While the
And yet mypy complains. I think it has something to do with the covariance/contravariance of
You could use a validator instead of a regex.
What's wrong with just always using |
for json-ld graph constructions. the dictionaries from which the enums are built have additional properties around those values.
we are validating through multiple routes using both python and json schema validator. regex's also apply to json schema. anyhttpurl is too general and also does not support regex's. the intent here is to be as specific as possible for both routes, and specialize in python only when necessary. regex's therefore support both routes to start with. |
|
should we resurrect this one? seems has aged enough, would need rebase etc... |
@yarikoptic I would like to resurrect this, but in order to be worthwhile, we would need to deal with the various issues listed in the first comment. (cc @satra) |
for AnyHttpUrl see this open issue: pydantic/pydantic#3143 (so just shifting to anyhttpurl won't solve the mypy issue). also we do have something specific that makes it httpurl, it seems forcing something to be more general just for static validation seems to be counter to the idea of specificity of elements. i welcome suggestions, but we should not move away from our overall goals of maintaining both a json schema that can do a fair bit of validating and pydantic, which can add additional validators. the dandi web app uses the json schema for validation, so we can't simply move away from those elements. |
I'm not saying we should move away from the JSON Schema, but I would like to know how the current enum metadata is consumed & used so that a static alternative can be devised. The dynamic enum generation is currently the biggest problem with getting mypy to be happy with this library, and I have yet to see a real reason why it's done the way it is. |
I would like to revive this development so we could get dandischema annotated and then dandi-cli. |
You mean rebase this PR against master, not merge this PR into master, right? |
correct. I guess I should have said "merge master in [this branch]" ;-) |
@yarikoptic Rebased. |
62a45ff
to
dd881dd
Compare
@satra - could you please re-review this PR, and follow up on existing discussions. It would be nice to finish up this PR and get it merged so the work doesn't get wasted and we get better type annotations checking through out. |
Meanwhile: I've rebased and force-pushed to get a fresh state. Locally I get "Found 132 errors in 7 files (checked 21 source files)", so delaying finishing it up causes the growth of annotations to "catch up on". I can promise keeping an eye on this PR to get it over the finish line if @jwodder makes another push to add missing annotations. |
@jwodder - there are several intentional tests for checking validation, which the type checker seems to pick up on as invalid. |
fine with me. |
which one is fine with you - 0.6.4 or 0.7.0 @satra? also any change in schema version results in dandi-cli testing going kaboom since dandi-archive is not accepting future/unknown version of the schema, so I guess we nohow tune up the docker compose setup while testing dandischema to use this particular dandischema "version" @jwodder ? |
i should have been clearer. for this |
Co-authored-by: Satrajit Ghosh <[email protected]>
Because the attempt at setting it dynamically doesn't actually produce any annotations
Looking at the changes exported schema introduces in https://github.com/dandi/dandi-schema/actions/runs/4325493337/jobs/7551722366 I think that they might (since would have needed to look at all uses where Enums were introduced) be compatible. But I can be wrong, time will show ;)
@satra At the moment, the following nontrivial issues are causing problems with the type checking:
https://github.com/dandi/dandischema/blob/62067fbb0184d51f2dd9ee415cf014f74249cd78/dandischema/models.py#L137-L138
The definition of
wasGeneratedBy
inDandiset
— which declares the field as aOptional[List[Project]]
— is incompatible with the definition of the field in the supertype — which declares it asOptional[List[Activity]]
.The definition of
url
inPublishedDandiset
— which declares the field as astr
— is incompatible with the definition of the field in the supertype — which declares it asOptional[HttpUrl]
. IfPublishedDandiset.url
is changed to anHttpUrl
, pydantic then complains about the field'sregex
parameter not applying.mypy doesn't like the overriding of
HttpUrl
based on an environment variable.