Repository: conan-io/conan

Issue:
[bug] Unable to use "specific names" as values for conf entries
### Environment details

* Operating System+version: Irrelevant
* Compiler+version: Irrelevant
* Conan version: 2.0.17 (packaged as exe with the pyinstaller script)
* Python version: 3.12


### Steps to reproduce

1. In any recipe, setting a conf value to any of the following values results in an error: [copy, re, fnmatch, OrderedDict]. This is probably because there are modules / types with the same name imported in the file where `eval` is run. That results in the value being interpreted as something other than a string. 

Dummy scenario:
conanfile.py
```python3
from conan import ConanFile


class dummy(ConanFile):
    name = "fixed_name"
    version = "1.2.3"

    def build(self):
        x = self.conf.get("user.company.conf:conf")
        self.output.warning("|" * 100)
        self.output.warning(type(x))
        self.output.warning(x)
        self.output.warning("|" * 100)
```

command:
```bash
conan build . -c "user.company.conf:conf=fnmatch"
```

### Logs

```
PS C:\E\ws\temp\New folder (3)> conan build . -c "user.company.conf:conf=re"
ERROR: It's not possible to compose module values and str ones.
PS C:\E\ws\temp\New folder (3)> conan build . -c "user.company.conf:conf=OrderedDict"
ERROR: It's not possible to compose type values and str ones.
PS C:\E\ws\temp\New folder (3)> conan build . -c "user.company.conf:conf=fnmatch"
ERROR: It's not possible to compose module values and str ones.
```


Discussion:
The suspected file where this issue is present is probably: `conans/model/conf.py` 
Particularly the function `_get_evaluated_value(__v)` in line: `643` (or line `653` in the current version)
Thanks very much for your report @mhabibav 

This is indeed a gap in the evaluation of confs, it didn't take into account the possibility of a match with an existing Python module. I am submitting a fix in https://github.com/conan-io/conan/pull/15779 for next 2.2 release.
Thanks for the quick fix. 
https://github.com/conan-io/conan/pull/15779 merged, it will be in next 2.2



Patch:
diff --git a/conans/model/conf.py b/conans/model/conf.py
index b736dfd3990..8174f963f8d 100644
--- a/conans/model/conf.py
+++ b/conans/model/conf.py
@@ -1,4 +1,5 @@
 import copy
+import numbers
 import re
 import os
 import fnmatch
@@ -650,20 +651,20 @@ def serialize(self):
         return result
 
     @staticmethod
-    def _get_evaluated_value(__v):
+    def _get_evaluated_value(_v):
         """
         Function to avoid eval() catching local variables
         """
         try:
-            # Isolated eval
-            parsed_value = eval(__v)  # This destroys Windows path strings with backslash
-            if isinstance(parsed_value, str):  # xxx:xxx = "my string"
+            value = eval(_v)  # This destroys Windows path strings with backslash
+        except:  # It means eval() failed because of a string without quotes
+            value = _v.strip()
+        else:
+            if not isinstance(value, (numbers.Number, bool, dict, list, set, tuple)) \
+                    and value is not None:
                 # If it is quoted string we respect it as-is
-                parsed_value = __v.strip()
-        except:
-            # It means eval() failed because of a string without quotes
-            parsed_value = __v.strip()
-        return parsed_value
+                value = _v.strip()
+        return value
 
     def loads(self, text, profile=False):
         self._pattern_confs = {}


Test patch:
diff --git a/conans/test/integration/configuration/conf/test_conf.py b/conans/test/integration/configuration/conf/test_conf.py
index 5a4ee37d7ae..61cb4ca95b3 100644
--- a/conans/test/integration/configuration/conf/test_conf.py
+++ b/conans/test/integration/configuration/conf/test_conf.py
@@ -396,3 +396,20 @@ def generate(self):
     assert "dep/0.1: user.myteam:myconf: ['root_value', 'value1']" in c.out
     # The pkg/0.1 output should be non-modified
     assert "pkg/0.1: user.myteam:myconf: ['root_value']" in c.out
+
+
+def test_especial_strings_fail():
+    # https://github.com/conan-io/conan/issues/15777
+    c = TestClient()
+    global_conf = textwrap.dedent("""
+        user.mycompany:myfile = re
+        user.mycompany:myother = fnmatch
+        user.mycompany:myfunct = re.search
+        user.mycompany:mydict = {1: 're', 2: 'fnmatch'}
+        """)
+    save(c.cache.new_config_path, global_conf)
+    c.run("config show *")
+    assert "user.mycompany:myfile: re" in c.out
+    assert "user.mycompany:myother: fnmatch" in c.out
+    assert "user.mycompany:myfunct: re.search" in c.out
+    assert "user.mycompany:mydict: {1: 're', 2: 'fnmatch'}" in c.out