-
Notifications
You must be signed in to change notification settings - Fork 37
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
Optional type inference #586
Optional type inference #586
Conversation
merge upstream changes
merge upstream
merge upstream changes
merge upstream changes
Thanks @jmosbacher ! I was a bit too quick to merge.
|
I used a regular warning, but do you think maybe a deprecation is more suitable? I'm on the fence. |
strax/config.py
Outdated
if infer_dtype is OMITTED and type is OMITTED and default is not OMITTED: | ||
warnings.warn(f'You are setting a default value for config {name} but not \ | ||
specifying a type. In the future the type will be inferred from \ | ||
the default value which will result in an error if this config \ | ||
is set to a different type.') | ||
|
||
if infer_dtype and type is OMITTED and default is not OMITTED: |
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 infer_dtype is OMITTED and type is OMITTED and default is not OMITTED: | |
warnings.warn(f'You are setting a default value for config {name} but not \ | |
specifying a type. In the future the type will be inferred from \ | |
the default value which will result in an error if this config \ | |
is set to a different type.') | |
if infer_dtype and type is OMITTED and default is not OMITTED: | |
if infer_dtype is OMITTED and type is OMITTED and default is not OMITTED: | |
warnings.warn(f'You are setting a default value for config {name} but not \ | |
specifying a type. In the future the type will be inferred from \ | |
the default value which will result in an error if this config \ | |
is set to a different type.') | |
elif infer_dtype and type is OMITTED and default is not OMITTED: |
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 i set infer_dtype=False
wouldnt this still infer the type?
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.
fair but if infer_dtype
is True
because it is a string, so we would get both a warning and later an error in the validate part.
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.
just edited the suggestion
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.
oops i pushed an edit before i noticed you also did...
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.
either is fine with me.
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.
yeah I think this many if statements are indeed a bit unnecessarily tars to follow but your method is good 👍
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.
But the logic didn't do anything right? You want to warn that this will fail?
Anyway, what I meant was that we could use a filter to prevent throwing the same warning 1000 times (but I'm not sure if we would, let's see)
I think a more fitting place to filter the warnings would be in straxen no? |
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, this helps indeed.
Maybe we should allow type to be a list of types or does a Ty.Union also work?
I think setting the type parameter to a tuple of types should work as is but I guess we could make that explicit in the type hint |
Addendum to #569, makes it optional so that we dont immediately break code that relies on the loophole created by issue 568. when we stop getting the warning in straxen tests we can enable the type inference by default.