Skip to content
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

Store ints as ints in the configuration object #1119

Merged
merged 5 commits into from
Sep 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions opentelemetry-api/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## Unreleased

- Store `int`s as `int`s in the global Configuration object
([#1118](https://github.com/open-telemetry/opentelemetry-python/pull/1118))

## Version 0.13b0

Released 2020-09-17
Expand Down
9 changes: 4 additions & 5 deletions opentelemetry-api/src/opentelemetry/configuration/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,10 @@ def __new__(cls) -> "Configuration":
try:
value = int(value_str)
except ValueError:
pass
try:
value = float(value_str)
except ValueError:
pass
try:
value = float(value_str)
except ValueError:
pass

instance._config_map[key] = value

Expand Down
15 changes: 6 additions & 9 deletions opentelemetry-api/tests/configuration/test_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,15 +119,12 @@ def test_boolean(self) -> None:
},
)
def test_integer(self) -> None:
self.assertEqual(
Configuration().POSITIVE_INTEGER, 123
) # pylint: disable=no-member
self.assertEqual(
Configuration().NEGATIVE_INTEGER, -123
) # pylint: disable=no-member
self.assertEqual(
Configuration().NON_INTEGER, "-12z3"
) # pylint: disable=no-member
# pylint: disable=no-member
self.assertIsInstance(Configuration().POSITIVE_INTEGER, int)
self.assertEqual(Configuration().POSITIVE_INTEGER, 123)
self.assertIsInstance(Configuration().NEGATIVE_INTEGER, int)
self.assertEqual(Configuration().NEGATIVE_INTEGER, -123)
self.assertEqual(Configuration().NON_INTEGER, "-12z3")
Copy link
Contributor

Choose a reason for hiding this comment

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

Curious how these tests passed before this change

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Before, we didn't have tests that checked type (added them here with isinstance). And this:

Python 3.8.3 (default, Jun 29 2020, 18:03:36) 
Type 'copyright', 'credits' or 'license' for more information
IPython 7.16.1 -- An enhanced Interactive Python. Type '?' for help.

In [1]: 1 == 1.0
Out[1]: True

In [2]: 

Copy link
Contributor

Choose a reason for hiding this comment

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

Ahhhhh right, that makes sense now.


@patch.dict(
"os.environ", # type: ignore
Expand Down