Can Python "os.environ.get" ever return a non-string?
<p>In this code <a href="https://github.com/chimpler/pyhocon/blob/master/pyhocon/config_parser.py#L291" rel="nofollow">here</a>, they use <code>os.environ</code> to get the value of an environment variable, and then immediately check to see if it is an instance of their custom classes.</p>

<pre><code>value = os.environ.get(variable)
...
elif isinstance(value, ConfigList) or isinstance(value, ConfigTree):
</code></pre>

<p>Is it actually possible that the <code>value</code> will be an instance of their custom classes? Is this dead code?</p>

<p>Anything that comes from the <em>outside</em> will be just a string, I guess.</p>

<p>On the other hand if you are adding something to the environment from the Python code, then you have just a bit more freedom.</p>

<p>Adding anything but a string still fails:</p>

<pre><code>&gt;&gt;&gt; os.environ['a'] = 89
Traceback (most recent call last):
  File "&lt;stdin&gt;", line 1, in &lt;module&gt;
  File "C:\Program Files\Python27\lib\os.py", line 420, in __setitem__
    putenv(key, item)
TypeError: must be string, not int
</code></pre>

<p>However, you could make your own class inherited from str:</p>

<pre><code>class C(str):
    pass

os.environ['a'] = C()
</code></pre>

<p>In Python2 this seems to do the trick:</p>

<pre><code>&gt;&gt;&gt; type(os.environ['a'])
&lt;class '__main__.C'&gt;
</code></pre>

<p>However, in Python 3 it does not. It looks like it just saves a string:</p>

<pre><code>&gt;&gt;&gt; type(os.environ['a'])
&lt;class 'str'&gt;
</code></pre>

<hr>

<p>Still, that does not explain the code from <a href="https://github.com/chimpler/pyhocon/blob/master/pyhocon/config_parser.py#L291" rel="nofollow">pyhocon</a>. I don't see how that object could be pushed into <code>os.environ</code>.</p>

<p>Unless they monkeypatched <code>os.environ</code>... In that case, anything would be possible.</p>

python environment-variables