title: How to check if an object is created with `with` statement?
body: <p>I would like to ensure that the class is only instantiated within a "with" statement.</p>
  
  <p>i.e. this one is ok:</p>
  
  <pre><code>with X() as x:
   ...
  </code></pre>
  
  <p>and this is not:</p>
  
  <pre><code>x = X()
  </code></pre>
  
  <p>How can I ensure such functionality?</p>