-
Notifications
You must be signed in to change notification settings - Fork 395
[NO-TICKET] Fix IncompatibleAssignment steep check
#5015
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
base: master
Are you sure you want to change the base?
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.
👍 Thanks for this + left a few notes!
| def initialize(duration_ext_ns:, input_truncated:) | ||
| @events = [] | ||
| @actions = @attributes = {} | ||
| @actions = {} | ||
| @attributes = {} |
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.
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.
Spot on, indeed a freeze makes sense here
lib/datadog/core/utils/time.rb
Outdated
| # | ||
| # @param unit [Symbol] unit for the resulting value, same as ::Process#clock_gettime, defaults to :float_second | ||
| # @return [Numeric] timestamp in the requested unit, since some unspecified starting point | ||
| # @return [Float] timestamp in the requested unit, since some unspecified starting point |
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.
| # @return [Float] timestamp in the requested unit, since some unspecified starting point | |
| # @return [Numeric] timestamp in the requested unit, since some unspecified starting point |
This change is not correct -- if you change the unit you can get non-floats (e.g. try calling it with :second):
[2] pry(main)> Datadog::Core::Utils::Time.get_time
=> 4634.229061201
[3] pry(main)> Datadog::Core::Utils::Time.get_time(:second)
=> 4637
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! Not sure why I changed it to Float only, but I think Numeric is too broad. I've changed it to Float|Integer according to https://github.com/ruby/rbs/blob/master/core/process.rbs#L624-L626
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 in 15a38cb
| # Steep: `Integer ** Integer` can also result in Rational (e.g. 10**-2) | ||
| # which is why it gives an error if NANOSECONDS is set to 10**9. |
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.
Minor: I suggest removing this comment. That's because, if you came across the new code, you'd never ask "Wait, why is this not 10**9 instead of 1_000_000_000, I must know the reason!!" ;)
I do understand the interest for this kind of comment, but this is a comment for the PR! Or at least as a commit message -- because it's a comment about the change from one to another. But going forward, we'll never need to care about this again.
| # Steep: `Integer ** Integer` can also result in Rational (e.g. 10**-2) | |
| # which is why it gives an error if NANOSECONDS is set to 10**9. |
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.
Applied in 15a38cb
lib/datadog/tracing/span_event.rb
Outdated
| # Steep: `Integer ** Integer` can also result in Rational (e.g. 10**-2) | ||
| # which is why it gives an error if MIN_INT64_SIGNED is set to -2**63. |
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.
Minor: Same as my note above -- this doesn't particularly need a comment going forward
| # Steep: `Integer ** Integer` can also result in Rational (e.g. 10**-2) | |
| # which is why it gives an error if MIN_INT64_SIGNED is set to -2**63. |
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.
Applied in 15a38cb
lib/datadog/tracing/span_event.rb
Outdated
| # DEV: This is incorrect, 2 << 63 - 1 is not the same as 2**63 - 1 (offset by 1). | ||
| # The correct formula is `(2 << 62) - 1`. Check if it is a breaking change before fixing it. | ||
| MAX_INT64_SIGNED = 2 << 63 - 1 |
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.
This is a nice catch, and indeed it's not correct -- there is an off-by-one here.
I think it's very much worth fixing, either on this PR or another; let's not just leave a comment here and move on ;)
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.
Fixed in 15a38cb
| # The only place where start_time_nano is called previously checks if span is stopped, | ||
| # which checks if @end_time is not nil, and the only place where @end_time is set is in stop, | ||
| # which also sets @start_time if it wasn't already set. | ||
| # @type ivar @start_time: ::Time | ||
| @start_time.to_i * 1000000000 + @start_time.nsec |
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.
Minor: Hmm... I'm not quite convinced about this override. In particular, it's based on the current state of non-local code, and who's going to remember to update this comment if any of the logic it's commenting on actually changes?
So I think it's better to have a steep:ignore than a "here's some potentially-misleading types" IMO?
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 agree, but at the same time, if someone uses that methods in a context where start_time might be nil, this will cause an error. I'll add a guard clause.
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.
Added in 15a38cb
BenchmarksBenchmark execution time: 2025-10-31 18:33:07 Comparing candidate commit 20e89c7 in PR branch Found 1 performance improvements and 2 performance regressions! Performance is the same for 41 metrics, 2 unstable metrics. scenario:line instrumentation - untargeted
scenario:method instrumentation
scenario:profiling - Allocations (baseline)
|
15a38cb to
20e89c7
Compare
Typing analysisNote: Ignored files are excluded from the next sections.
|
|
✅ Tests 🎉 All green!❄️ No new flaky tests detected 🎯 Code Coverage 🔗 Commit SHA: 20e89c7 | Docs | Datadog PR Page | Was this helpful? Give us feedback! |
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 understand why 2**63-1 does not fit into a signed int64, can you clarify?
| class Context | ||
| ActiveContextError = Class.new(StandardError) | ||
| # Steep: https://github.com/soutaro/steep/issues/1880 | ||
| ActiveContextError = Class.new(StandardError) # steep:ignore IncompatibleAssignment |
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 use class ActiveContextError < StandardError does steep then work?
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 it does but I remember that @Strech preferred to keep it as is, which is why I've added a comment with the issue, and disabled it
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 think type definition as such should work, no? But code could stay the same
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 got it now, << vs **
| def initialize(duration_ext_ns:, input_truncated:) | ||
| @events = [] | ||
| @actions = @attributes = {} | ||
| @actions = {} | ||
| @attributes = {} |
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.
Spot on, indeed a freeze makes sense here
| class Builder | ||
| InvalidOptionError = Class.new(StandardError) | ||
| # Steep: https://github.com/soutaro/steep/issues/1880 | ||
| InvalidOptionError = Class.new(StandardError) # steep:ignore IncompatibleAssignment |
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.
Sorry, but will this work?
class InvalidOptionError < StandardError
end
| # | ||
| # @param unit [Symbol] unit for the resulting value, same as ::Process#clock_gettime, defaults to :float_second | ||
| # @return [Numeric] timestamp in the requested unit, since some unspecified starting point | ||
| # @return [Float|Integer] timestamp in the requested unit, since some unspecified starting point |
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.
❤️
What does this PR do?
Remove IncompatibleAssignment exclusion from the Steepfile and fixes related issues.
Motivation:
Improve typing on dd-trace-rb.
Change log entry
None.
Additional Notes:
How to test the change?
bundle exec rake steep:check