Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't set a break inside class property #4

Open
krvkir opened this issue Dec 8, 2017 · 2 comments
Open

Can't set a break inside class property #4

krvkir opened this issue Dec 8, 2017 · 2 comments

Comments

@krvkir
Copy link

krvkir commented Dec 8, 2017

The following code causes an error:

%load_ext xdbg

class MyClass:
    @property
    def a(self):
        return 1

%break MyClass.a ?
---------------------------------------------------------------------------

TypeError                                 Traceback (most recent call last)

<ipython-input-1-38157ca90447> in <module>()
      6         return 1
      7 
----> 8 get_ipython().magic('break MyClass.a ?')


C:\Users\Krasnoshekov_KI\AppData\Local\Continuum\Anaconda3\lib\site-packages\IPython\core\interactiveshell.py in magic(self, arg_s)
   2156         magic_name, _, magic_arg_s = arg_s.partition(' ')
   2157         magic_name = magic_name.lstrip(prefilter.ESC_MAGIC)
-> 2158         return self.run_line_magic(magic_name, magic_arg_s)
   2159 
   2160     #-------------------------------------------------------------------------


C:\Users\Krasnoshekov_KI\AppData\Local\Continuum\Anaconda3\lib\site-packages\IPython\core\interactiveshell.py in run_line_magic(self, magic_name, line)
   2077                 kwargs['local_ns'] = sys._getframe(stack_depth).f_locals
   2078             with self.builtin_trap:
-> 2079                 result = fn(*args,**kwargs)
   2080             return result
   2081 


<decorator-gen-125> in break_(self, args, temporary)


C:\Users\Krasnoshekov_KI\AppData\Local\Continuum\Anaconda3\lib\site-packages\IPython\core\magic.py in <lambda>(f, *a, **k)
    186     # but it's overkill for just that one bit of state.
    187     def magic_deco(arg):
--> 188         call = lambda f, *a, **k: f(*a, **k)
    189 
    190         if callable(arg):


c:\users\krasnoshekov_ki\opt\xdbg\xdbg\xdbg.py in break_(self, args, temporary)
    168 
    169                 if lineno == '?':
--> 170                     lines, starting_lineno = inspect.getsourcelines(func)
    171                     for line, i in zip(lines, range(starting_lineno, starting_lineno + len(lines))):
    172                         print('{}  '.format(i), line, end='')


C:\Users\Krasnoshekov_KI\AppData\Local\Continuum\Anaconda3\lib\inspect.py in getsourcelines(object)
    923     raised if the source code cannot be retrieved."""
    924     object = unwrap(object)
--> 925     lines, lnum = findsource(object)
    926 
    927     if ismodule(object):


C:\Users\Krasnoshekov_KI\AppData\Local\Continuum\Anaconda3\lib\inspect.py in findsource(object)
    736     is raised if the source code cannot be retrieved."""
    737 
--> 738     file = getsourcefile(object)
    739     if file:
    740         # Invalidate cache if needed.


C:\Users\Krasnoshekov_KI\AppData\Local\Continuum\Anaconda3\lib\inspect.py in getsourcefile(object)
    652     Return None if no way can be identified to get the source.
    653     """
--> 654     filename = getfile(object)
    655     all_bytecode_suffixes = importlib.machinery.DEBUG_BYTECODE_SUFFIXES[:]
    656     all_bytecode_suffixes += importlib.machinery.OPTIMIZED_BYTECODE_SUFFIXES[:]


C:\Users\Krasnoshekov_KI\AppData\Local\Continuum\Anaconda3\lib\inspect.py in getfile(object)
    634         return object.co_filename
    635     raise TypeError('{!r} is not a module, class, method, '
--> 636                     'function, traceback, frame, or code object'.format(object))
    637 
    638 def getmodulename(path):


TypeError: <property object at 0x0000013A3AC726D8> is not a module, class, method, function, traceback, frame, or code object
%break MyClass.a 1
---------------------------------------------------------------------------

AttributeError                            Traceback (most recent call last)

<ipython-input-2-a386d7310f21> in <module>()
----> 1 get_ipython().magic('break MyClass.a 1')


C:\Users\Krasnoshekov_KI\AppData\Local\Continuum\Anaconda3\lib\site-packages\IPython\core\interactiveshell.py in magic(self, arg_s)
   2156         magic_name, _, magic_arg_s = arg_s.partition(' ')
   2157         magic_name = magic_name.lstrip(prefilter.ESC_MAGIC)
-> 2158         return self.run_line_magic(magic_name, magic_arg_s)
   2159 
   2160     #-------------------------------------------------------------------------


C:\Users\Krasnoshekov_KI\AppData\Local\Continuum\Anaconda3\lib\site-packages\IPython\core\interactiveshell.py in run_line_magic(self, magic_name, line)
   2077                 kwargs['local_ns'] = sys._getframe(stack_depth).f_locals
   2078             with self.builtin_trap:
-> 2079                 result = fn(*args,**kwargs)
   2080             return result
   2081 


<decorator-gen-125> in break_(self, args, temporary)


C:\Users\Krasnoshekov_KI\AppData\Local\Continuum\Anaconda3\lib\site-packages\IPython\core\magic.py in <lambda>(f, *a, **k)
    186     # but it's overkill for just that one bit of state.
    187     def magic_deco(arg):
--> 188         call = lambda f, *a, **k: f(*a, **k)
    189 
    190         if callable(arg):


c:\users\krasnoshekov_ki\opt\xdbg\xdbg\xdbg.py in break_(self, args, temporary)
    173                     print()
    174                 else:
--> 175                     num = add_breakpoint(self.breakpoint_table, func, lineno)
    176                     self.breakpoint_table.modify_breakpoints([num], temporary=temporary)
    177                     print('New breakpoint', num)


c:\users\krasnoshekov_ki\opt\xdbg\xdbg\breakpoint_hooks.py in add_breakpoint(table, func, lineno)
     89 
     90 def add_breakpoint(table, func, lineno=None):
---> 91     b = bp.Code.from_code(func.__code__)
     92 
     93     inject_index = 0


AttributeError: 'property' object has no attribute '__code__'
@nikitakit
Copy link
Owner

Thanks for opening the issue! I should figure out how to handle properties so that errors aren't thrown, though I'll need to think about this since they can have both getters and setters.

For now, you should be able to do %break MyClass.a.fget ? (and likewise for fset and fdel, if you have a separate setter or deleter defined)

@krvkir
Copy link
Author

krvkir commented Dec 8, 2017

Thank you for the hint about fset and the company, I completely forgot about them (my bad).

Maybe the proper way to resolve the ambiguity would be to inspect how many property handlers are declared, and if there's only one (e.g. only fget), choose it without bothering the user; otherwise report an error with a list of options.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants