@@ -177,18 +177,12 @@ Retrieving the variable names from inside a function call/class instantiation
177177 # Since v0.1.3
178178 # We can ask varname to raise exceptions
179179 # if it fails to detect the variable name
180-
181- from varname import VarnameRetrievingError
182- def get_name ():
183- try :
184- # if raise_exc is False
185- # "var_<index>" will be returned
186- return varname(raise_exc = True )
187- except VarnameRetrieveingError:
188- return None
180+ def get_name (raise_exc ):
181+ return varname(raise_exc = raise_exc)
189182
190183 a = {}
191- a[' b' ] = get_name() # None
184+ a[' b' ] = get_name(True ) # VarnameRetrievingError
185+ a[' b' ] = get_name(False ) # None
192186
193187 Value wrapper
194188^^^^^^^^^^^^^
@@ -244,7 +238,7 @@ Detecting next immediate attribute name
244238 self .will = None
245239
246240 def permit (self ):
247- self .will = will()
241+ self .will = will(raise_exc = False )
248242 if self .will == ' do' :
249243 # let self handle do
250244 return self
@@ -296,16 +290,21 @@ Injecting ``__varname__``
296290 b.append(1 )
297291 a == b
298292
299- Limitations
300- -----------
293+ Reliability and limitations
294+ ---------------------------
301295
302296``python-varname `` is all depending on ``executing `` package to look for the node.
303- It does not work with any environment where ``executing `` is not able to detect the node.
297+ The node ``executing `` detects is ensured to be the correct one (see `this <https://github.com/alexmojaki/executing#is-it-reliable >`_\ ).
298+
299+ It partially works with environments where other AST magics apply, including
300+ ``pytest ``\ , ``ipython ``\ , ``macropy ``\ , ``birdseye ``\ , ``reticulate `` with ``R ``\ , etc. Neither
301+ ``executing `` nor ``python-varname `` is 100% working with those environments. Use
302+ it at your own risk.
303+
304304For example:
305305
306306
307307*
308- Environments where other AST magics apply. For example: ``pytest ``\ , ``ipython ``\ , ``macropy ``\ , or ``birdseye ``.
309308 This will not work with ``pytest ``\ :
310309
311310 .. code-block :: python
@@ -317,4 +316,13 @@ For example:
317316 name_a = nameof(a)
318317 assert name_a == ' a'
319318
319+ *
320+ This will also typically fail with ``ipython ``\ :
321+
322+ .. code-block :: python
323+
324+ a = 1
325+ for _ in [0 ]:
326+ print (nameof(a))
327+
320328 * ``R `` with ``reticulate ``.
0 commit comments