Skip to content

Use of "iterable" Type May Need Re-Evaluation Across the Repo #784

Merged
brettmc merged 19 commits into
open-telemetry:mainfrom
amber0612:main
Aug 1, 2022
Merged

Use of "iterable" Type May Need Re-Evaluation Across the Repo #784
brettmc merged 19 commits into
open-telemetry:mainfrom
amber0612:main

Conversation

@amber0612

@amber0612 amber0612 commented Jul 25, 2022

Copy link
Copy Markdown
Contributor

No description provided.

@codecov

codecov Bot commented Jul 25, 2022

Copy link
Copy Markdown

Codecov Report

Merging #784 (d0b6e49) into main (bf912ed) will increase coverage by 0.10%.
The diff coverage is 100.00%.

❗ Current head d0b6e49 differs from pull request most recent head 22be517. Consider uploading reports for the commit 22be517 to get more accurate results

Impacted file tree graph

@@             Coverage Diff              @@
##               main     #784      +/-   ##
============================================
+ Coverage     79.37%   79.48%   +0.10%     
+ Complexity     1407     1406       -1     
============================================
  Files           160      160              
  Lines          3477     3470       -7     
============================================
- Hits           2760     2758       -2     
+ Misses          717      712       -5     
Flag Coverage Δ
7.4 79.48% <100.00%> (+0.10%) ⬆️
8.0 79.54% <100.00%> (+0.10%) ⬆️
8.1 79.54% <100.00%> (+0.10%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/SDK/Common/Util/functions.php 100.00% <ø> (+23.80%) ⬆️
src/SDK/Trace/Behavior/SpanExporterTrait.php 100.00% <ø> (ø)
src/SDK/Metrics/Exporters/AbstractExporter.php 75.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update bf912ed...22be517. Read the comment docs.

@amber0612
amber0612 marked this pull request as draft July 25, 2022 07:30
@amber0612
amber0612 marked this pull request as ready for review July 25, 2022 07:45

@Nevay Nevay left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Failing test:

assert(isEmpty((fn() => yield from [])()));

$generator = gen();
foreach ($generator as $value) {
}
$value=isEmpty($generator) ? true : false;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Obsolete ternary operator

@amber0612 amber0612 Jul 25, 2022

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved :)

@Nevay

Nevay commented Jul 25, 2022

Copy link
Copy Markdown
Contributor

Another failing test:

$generator = (fn() => yield from [1, 2])();
$generator->next();
assert(!isEmpty($generator));

@amber0612

Copy link
Copy Markdown
Contributor Author

$generator = (fn() => yield from [1, 2])();
$generator->next();
assert(!isEmpty($generator));

This is a non empty generator case and hence isEmpty() will return false. Hence the test case is passing

@Nevay

Nevay commented Jul 25, 2022

Copy link
Copy Markdown
Contributor

isEmpty() will return false

Currently it returns true (foreach tries to rewind the generator and triggers an exception).


What is the expected result for an exhausted rewindable iterator?

$iterator = new ArrayIterator([1]);
$iterator->next();
$empty = isEmpty($iterator); // ?

Should isEmpty() be allowed to modify the given iterable (somewhat obsolete if we mark the function as internal)?

$iterator = new ArrayIterator([1, 2]);
$iterator->next();
isEmpty($iterator);
$value = $iterator->current(); // ?

Side note: We could simply remove the special handling of an empty batch and the isEmpty() function, our span processors call SpanExporter::export() with a non-empty batch / exporters can skip empty exports after conversion.

@amber0612

Copy link
Copy Markdown
Contributor Author

Makes sense. The iterable will be modified.

@amber0612
amber0612 marked this pull request as draft July 27, 2022 05:36
@amber0612 amber0612 changed the title Unit Test for isEmpty function for Iterables Use of "iterable" Type May Need Re-Evaluation Across the Repo Jul 27, 2022
@amber0612
amber0612 marked this pull request as ready for review July 27, 2022 11:57
@amber0612
amber0612 marked this pull request as draft July 27, 2022 11:57
@amber0612
amber0612 marked this pull request as ready for review July 27, 2022 12:54
@brettmc
brettmc merged commit 73f5106 into open-telemetry:main Aug 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants