microsoft / ptvsd

Python debugger package for use with Visual Studio and Visual Studio Code.
Other
550 stars 68 forks source link

repr () sometimes not being called to display a namedtuple value. #2058

Closed mrolle45 closed 4 years ago

mrolle45 commented 4 years ago

Environment data

Actual behavior

I define a subclass of namedtuple:

class FieldCurrInfo (namedtuple ('FieldCurrInfo', 'key, val, cells', defaults = [None, None, ()])):
    def add (self, val, cell):
        return self._replace (key = cell.key, val = val, cells = self.cells + (cell, ))
    @property
    def all_bits (self): return merge_bits ((cell.key for cell in self.cells))

    def __repr__ (self):
        return f'{self.key} {self.val}' if self.cells else '<empty>'

curr = FieldCurrInfo () # displays as I have a variable called 'cell', which shows as

Name Value Type
cell 0000_0000_0080_0000 TEX_HEADER_TEXTURE_TYPE OperandCell

curr.add (1, cell) -- displays in Locals as

  Name Value Type

◢ | curr | <FieldCurrInfo, len() = 0x3> | FieldCurrInfo   | ▶ 0 | 0000_0000_0080_0000 | RowKey   | 1 | 0x1 | int   | ▶ 2 | (0000_0000_0080_0000 ...XTURE_TYPE,) | tuple   | ▶ all_bits | 0000_0000_0080_0000 | RowKey   | ▶ cells | (0000_0000_0080_0000 ...XTURE_TYPE,) | tuple   | ▶ key | 0000_0000_0080_0000 | RowKey   | val | 0x1 | int   | ▶ _field_defaults | {'cells': (), 'key': None, 'val': None} | dict   | ▶ _fields | ('key', 'val', 'cells') | tuple   | ▶ _fields_defaults | {'cells': (), 'key': None, 'val': None} | dict   | len | 0x3 | int

Expected behavior

curr should show as: '0000_0000_0080_0000 1' which is repr (curr)

Steps to reproduce:

See above. Run the three lines of Python and observe 'curr' in the Locals window.

Here's output from Help/About Visual Studio: Microsoft Visual Studio Professional 2017 Version 15.9.16 VisualStudio.15.Release/15.9.16+28307.858 Microsoft .NET Framework Version 4.8.03752

Installed Version: Professional

Visual C++ 2017 00369-60000-00001-AA814 Microsoft Visual C++ 2017

ASP.NET and Web Tools 2017 15.9.04012.0 ASP.NET and Web Tools 2017

Azure App Service Tools v3.0.0 15.9.03024.0 Azure App Service Tools v3.0.0

C# Tools 2.10.0-beta2-63501-03+b9fb1610c87cccc8ceb74a770dba261a58e39c4a C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Common Azure Tools 1.10 Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.

Cookiecutter 15.9.18254.1 Provides tools for finding, instantiating and customizing templates in cookiecutter format.

Devart Code Compare 5.2.170 Devart Code Compare Copyright (c) 2012-2019 Devart. All rights reserved. http://www.devart.com/codecompare/

JavaScript Language Service 2.0 JavaScript Language Service

Microsoft Azure Tools 2.9 Microsoft Azure Tools for Microsoft Visual Studio 2017 - v2.9.20417.1

Microsoft JVM Debugger 1.0 Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines

Microsoft MI-Based Debugger 1.0 Provides support for connecting Visual Studio to MI compatible debuggers

Microsoft Visual C++ Wizards 1.0 Microsoft Visual C++ Wizards

Microsoft Visual Studio VC Package 1.0 Microsoft Visual Studio VC Package

MLGen Package Extension 1.0 MLGen Package Visual Studio Extension Detailed Info

NuGet Package Manager 4.6.0 NuGet Package Manager in Visual Studio. For more information about NuGet, visit http://docs.nuget.org/.

NVIDIA Nsight Visual Studio Edition 2019.2.0.19109 NVIDIA Nsight Visual Studio Edition provides tools for GPGPU and graphics development. Copyright © NVIDIA 2010 - 2019. •Direct3D® and DirectX® are registered trademarks of Microsoft Corporation in the United States and/or other countries. •Microsoft Detours is used under the Professional license (http://research.microsoft.com/en-us/projects/detours/). •Gardens Point Parser Generator Copyright 2005 Queensland University of Technology (QUT). All rights reserved. •NLog Copyright © 2004-2006 Jaroslaw Kowalski (jaak@jkowalski.net) •IronPython and WPFToolkit used under Microsoft Public License (Ms-PL) and are Copyright © Microsoft Corporation •Portions of RadControls for WPF © 2010-2011 by Telerik Corporation. All rights reserved. •zlib and libpng used under the zlib/libpnc license (http://opensource.org/licenses/Zlib) •QtSingleApplication Copyright 2013 Digia Plc and/or its subsidiary(-ies). •Font Awesome Copyright 2018 Fonticons, Inc.

Warning: This computer program is protected by copyright law and international treaties. Unauthorized reproduction or distribution of this program, or any portion of it, may result in severe civil and criminal penalties, and will be prosecuted to the maximum extent possible under the law.

NVIDIA Nsight Visual Studio Edition - CUDA support 2019.2.0.19109 NVIDIA Nsight Visual Studio Edition - CUDA support provides tools for CUDA development and debugging.

ProjectServicesPackage Extension 1.0 ProjectServicesPackage Visual Studio Extension Detailed Info

Python 15.9.18254.1 Provides IntelliSense, projects, templates, debugging, interactive windows, and other support for Python developers.

Python - Django support 15.9.18254.1 Provides templates and integration for the Django web framework.

Python - IronPython support 15.9.18254.1 Provides templates and integration for IronPython-based projects.

Python - Profiling support 15.9.18254.1 Profiling support for Python projects.

Test Adapter for Boost.Test 1.0 Enables Visual Studio's testing tools with unit tests written for Boost.Test. The use terms and Third Party Notices are available in the extension installation directory.

Test Adapter for Google Test 1.0 Enables Visual Studio's testing tools with unit tests written for Google Test. The use terms and Third Party Notices are available in the extension installation directory.

TypeScript Tools 15.9.30718.2001 TypeScript Tools for Microsoft Visual Studio

Visual Basic Tools 2.10.0-beta2-63501-03+b9fb1610c87cccc8ceb74a770dba261a58e39c4a Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Visual Studio Code Debug Adapter Host Package 1.0 Interop layer for hosting Visual Studio Code debug adapters in Visual Studio

Visual Studio Tools for CMake 1.0 Visual Studio Tools for CMake

VisualSVN 6.6.0 Integration with Subversion version control. For more information about VisualSVN, see the VisualSVN website at https://www.visualsvn.com Copyright © 2019 VisualSVN Software Ltd. All rights reserved.

mrolle45 commented 4 years ago

As a clue to this behavior, the display misbehaves if curr.cells is either a tuple or a list. If I have an object such as FieldCurrInfo (cell.key, 1, 3), it displays correctly.