From e7dc0e8179622a10556b247d73581589e187e13e Mon Sep 17 00:00:00 2001 From: Diego Hurtado Date: Wed, 16 Sep 2020 01:29:22 -0600 Subject: [PATCH 1/2] Store ints as ints in the configuration object Fixes #1118 --- opentelemetry-api/CHANGELOG.md | 2 ++ .../src/opentelemetry/configuration/__init__.py | 9 ++++----- .../tests/configuration/test_configuration.py | 15 ++++++--------- 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/opentelemetry-api/CHANGELOG.md b/opentelemetry-api/CHANGELOG.md index f058be37027..6897c773bb2 100644 --- a/opentelemetry-api/CHANGELOG.md +++ b/opentelemetry-api/CHANGELOG.md @@ -2,6 +2,8 @@ ## Unreleased +- Store `int`s as `int`s in the global Configuration object + ([#1118](https://github.com/open-telemetry/opentelemetry-python/pull/1118)) - Refactor `SpanContext.is_valid` from a method to a data attribute ([#1005](https://github.com/open-telemetry/opentelemetry-python/pull/1005)) - Moved samplers from API to SDK diff --git a/opentelemetry-api/src/opentelemetry/configuration/__init__.py b/opentelemetry-api/src/opentelemetry/configuration/__init__.py index 0c606b5af4d..286bfa7ac62 100644 --- a/opentelemetry-api/src/opentelemetry/configuration/__init__.py +++ b/opentelemetry-api/src/opentelemetry/configuration/__init__.py @@ -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 diff --git a/opentelemetry-api/tests/configuration/test_configuration.py b/opentelemetry-api/tests/configuration/test_configuration.py index 557591513b8..4e938632781 100644 --- a/opentelemetry-api/tests/configuration/test_configuration.py +++ b/opentelemetry-api/tests/configuration/test_configuration.py @@ -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.assertTrue(isinstance(Configuration().POSITIVE_INTEGER, int)) + self.assertEqual(Configuration().POSITIVE_INTEGER, 123) + self.assertTrue(isinstance(Configuration().NEGATIVE_INTEGER, int)) + self.assertEqual(Configuration().NEGATIVE_INTEGER, -123) + self.assertEqual(Configuration().NON_INTEGER, "-12z3") @patch.dict( "os.environ", # type: ignore From a5e897724bec0ee950879c5d1ec88f9ce4892c85 Mon Sep 17 00:00:00 2001 From: alrex Date: Mon, 21 Sep 2020 09:09:49 -0700 Subject: [PATCH 2/2] Apply suggestions from code review --- opentelemetry-api/tests/configuration/test_configuration.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/opentelemetry-api/tests/configuration/test_configuration.py b/opentelemetry-api/tests/configuration/test_configuration.py index 4e938632781..45ed9627d89 100644 --- a/opentelemetry-api/tests/configuration/test_configuration.py +++ b/opentelemetry-api/tests/configuration/test_configuration.py @@ -120,9 +120,9 @@ def test_boolean(self) -> None: ) def test_integer(self) -> None: # pylint: disable=no-member - self.assertTrue(isinstance(Configuration().POSITIVE_INTEGER, int)) + self.assertIsInstance(Configuration().POSITIVE_INTEGER, int) self.assertEqual(Configuration().POSITIVE_INTEGER, 123) - self.assertTrue(isinstance(Configuration().NEGATIVE_INTEGER, int)) + self.assertIsInstance(Configuration().NEGATIVE_INTEGER, int) self.assertEqual(Configuration().NEGATIVE_INTEGER, -123) self.assertEqual(Configuration().NON_INTEGER, "-12z3")