spyder-ide / spyder

Official repository for Spyder - The Scientific Python Development Environment
https://www.spyder-ide.org
MIT License
8.31k stars 1.61k forks source link

AttributeError in the kernel when modifying `locals` #19145

Closed BasSandor closed 2 years ago

BasSandor commented 2 years ago

Description

What steps will reproduce the problem?

I run a function in a seperate script. The function natively runs with magic numbers hard-coded into the functions. However, the functiona accepts **kwargs such that the locals() function may be altered using locals().update(). For example:

def func(**kwargs):
    a = b
    locals().update(kwargs)

Now, in the external script we run:

def main():
    func(a = c)

The problem occurs when I try to debug this file and when I manually map c to a using

locals().update({a:c}).

Traceback

Exception in comms call get_namespace_view:
  File "/Users/Bas/opt/anaconda3/envs/spyder-env/lib/python3.9/site-packages/spyder_kernels/comms/commbase.py", line 343, in _handle_remote_call
    return_value = self._remote_callback(
  File "/Users/Bas/opt/anaconda3/envs/spyder-env/lib/python3.9/site-packages/spyder_kernels/comms/frontendcomm.py", line 270, in _remote_callback
    return super(FrontendComm, self)._remote_callback(
  File "/Users/Bas/opt/anaconda3/envs/spyder-env/lib/python3.9/site-packages/spyder_kernels/comms/commbase.py", line 356, in _remote_callback
    return self._remote_call_handlers[call_name](
  File "/Users/Bas/opt/anaconda3/envs/spyder-env/lib/python3.9/site-packages/spyder_kernels/console/kernel.py", line 194, in get_namespace_view
    view = make_remote_view(ns, settings, EXCLUDED_NAMES)
  File "/Users/Bas/opt/anaconda3/envs/spyder-env/lib/python3.9/site-packages/spyder_kernels/utils/nsview.py", line 682, in make_remote_view
    data = get_remote_data(data, settings, mode='editable',
  File "/Users/Bas/opt/anaconda3/envs/spyder-env/lib/python3.9/site-packages/spyder_kernels/utils/nsview.py", line 665, in get_remote_data
    return globalsfilter(
  File "/Users/Bas/opt/anaconda3/envs/spyder-env/lib/python3.9/site-packages/spyder_kernels/utils/nsview.py", line 598, in globalsfilter
    (exclude_private and key.startswith('_')) or
AttributeError: 'int' object has no attribute 'startswith'
Exception in comms call get_var_properties:
  File "/Users/Bas/opt/anaconda3/envs/spyder-env/lib/python3.9/site-packages/spyder_kernels/comms/commbase.py", line 343, in _handle_remote_call
    return_value = self._remote_callback(
  File "/Users/Bas/opt/anaconda3/envs/spyder-env/lib/python3.9/site-packages/spyder_kernels/comms/frontendcomm.py", line 270, in _remote_callback
    return super(FrontendComm, self)._remote_callback(
  File "/Users/Bas/opt/anaconda3/envs/spyder-env/lib/python3.9/site-packages/spyder_kernels/comms/commbase.py", line 356, in _remote_callback
    return self._remote_call_handlers[call_name](
  File "/Users/Bas/opt/anaconda3/envs/spyder-env/lib/python3.9/site-packages/spyder_kernels/console/kernel.py", line 207, in get_var_properties
    data = get_remote_data(ns, settings, mode='editable',
  File "/Users/Bas/opt/anaconda3/envs/spyder-env/lib/python3.9/site-packages/spyder_kernels/utils/nsview.py", line 665, in get_remote_data
    return globalsfilter(
  File "/Users/Bas/opt/anaconda3/envs/spyder-env/lib/python3.9/site-packages/spyder_kernels/utils/nsview.py", line 598, in globalsfilter
    (exclude_private and key.startswith('_')) or
AttributeError: 'int' object has no attribute 'startswith'

Versions

Dependencies

# Mandatory:
applaunchservices >=0.1.7     :  0.3.0 (OK)
atomicwrites >=1.2.0          :  1.4.0 (OK)
chardet >=2.0.0               :  5.0.0 (OK)
cloudpickle >=0.5.0           :  2.1.0 (OK)
cookiecutter >=1.6.0          :  2.1.1 (OK)
diff_match_patch >=20181111   :  20200713 (OK)
intervaltree >=3.0.2          :  3.0.2 (OK)
IPython >=7.31.1;<8.0.0       :  7.33.0 (OK)
jedi >=0.17.2;<0.19.0         :  0.18.1 (OK)
jellyfish >=0.7               :  0.9.0 (OK)
jsonschema >=3.2.0            :  4.6.0 (OK)
keyring >=17.0.0              :  23.6.0 (OK)
nbconvert >=4.0               :  6.5.0 (OK)
numpydoc >=0.6.0              :  1.4.0 (OK)
parso >=0.7.0;<0.9.0          :  0.8.3 (OK)
pexpect >=4.4.0               :  4.8.0 (OK)
pickleshare >=0.4             :  0.7.5 (OK)
psutil >=5.3                  :  5.9.1 (OK)
pygments >=2.0                :  2.12.0 (OK)
pylint >=2.5.0                :  2.14.3 (OK)
pyls_spyder >=0.4.0           :  0.4.0 (OK)
pylsp >=1.4.1;<1.5.0          :  1.4.1 (OK)
pylsp_black >=1.2.0           :  1.2.1 (OK)
qdarkstyle >=3.0.2;<3.1.0     :  3.0.2 (OK)
qstylizer >=0.1.10            :  0.2.1 (OK)
qtawesome >=1.0.2             :  1.1.1 (OK)
qtconsole >=5.3.0;<5.4.0      :  5.3.1 (OK)
qtpy >=2.1.0                  :  2.1.0 (OK)
rtree >=0.9.7                 :  1.0.0 (OK)
setuptools >=49.6.0           :  62.6.0 (OK)
sphinx >=0.6.6                :  5.0.2 (OK)
spyder_kernels >=2.3.1;<2.4.0 :  2.3.1 (OK)
textdistance >=4.2.0          :  4.2.2 (OK)
three_merge >=0.1.1           :  0.1.1 (OK)
watchdog >=0.10.3             :  2.1.9 (OK)
zmq >=22.1.0                  :  23.2.0 (OK)

# Optional:
cython >=0.21                 :  None (NOK)
matplotlib >=3.0.0            :  3.5.1 (OK)
numpy >=1.7                   :  1.22.3 (OK)
pandas >=1.1.1                :  1.4.2 (OK)
scipy >=0.17.0                :  1.8.1 (OK)
sympy >=0.7.3                 :  None (NOK)
ccordoba12 commented 2 years ago

Hey @BasSandor, thanks for reporting. We'll try to fix this bug in our next version after 5.3.3, to be released in mid-October. In the meantime, please stop modifying locals or you'll keep getting the same error.