Skip to content

Commit

Permalink
Fix up docstring formatting.
Browse files Browse the repository at this point in the history
  • Loading branch information
visemet committed Mar 12, 2022
1 parent 862b5f6 commit 25fc602
Show file tree
Hide file tree
Showing 11 changed files with 19 additions and 20 deletions.
1 change: 1 addition & 0 deletions gdbmongo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# limitations under the License.
###
"""The gdbmongo package contains GDB pretty printers and commands for debugging the MongoDB Server.
Its primary target audience is MongoDB employees.
"""

Expand Down
5 changes: 2 additions & 3 deletions gdbmongo/abseil_printers.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ def gdb_resolve_type(typ: gdb.Type, /) -> gdb.Type:
"""Look up the name of a C++ type with any typedefs, pointers, and references stripped.
This function is useful in contexts where template arguments can be pointers because GDB may not
load the fields of the templated entity otherwise."""

load the fields of the templated entity otherwise.
"""
typ = typ.strip_typedefs()

while typ.code in (gdb.TYPE_CODE_PTR, gdb.TYPE_CODE_REF):
Expand All @@ -44,7 +44,6 @@ def AbslHashContainerIterator(container: gdb.Value, /) -> typing.Iterator[gdb.Va
"""Return a generator of every node in the given absl::container_internal::raw_hash_set or
derived class.
"""

capacity = int(container["capacity_"])
ctrl = container["ctrl_"]
slots = container["slots_"]
Expand Down
3 changes: 2 additions & 1 deletion gdbmongo/decorable_printer.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ class DecorationContainerPrinter(PrettyPrinterProtocol, SupportsDisplayHint):
# pylint: disable=missing-function-docstring
"""Pretty-printer for mongo::DecorationContainer<DecoratedType>.
This includes MongoDB types like ServiceContext, Client, and OperationContext."""
This includes MongoDB types like ServiceContext, Client, and OperationContext.
"""

symbol_name_regexp = re.compile(r"^(.*) in ")
type_name_regexp = re.compile(r"^(.*[\w>])([\s\*]*)$")
Expand Down
13 changes: 7 additions & 6 deletions gdbmongo/detect_toolchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

class ToolchainInfo(typing.NamedTuple):
"""Info about the MongoDB toolchain used to compile an executable."""

compiler: typing.Optional[str]
libstdcxx_python_home: typing.Optional[pathlib.Path]

Expand All @@ -51,8 +52,8 @@ def readelf(cls, executable: StrOrBytesPath, /) -> bytes:
"""Return the ELF .comment section of the executable.
The ELF .comment section contains information about which compiler(s) were used in building
the executable."""

the executable.
"""
with tempfile.NamedTemporaryFile() as output_file:
result = subprocess.run(
[cls.objcopy, "--dump-section", f".comment={str(output_file.name)}", executable],
Expand All @@ -76,8 +77,8 @@ def parse_gcc_version(
"""Extract the GCC compiler version from the ELF .comment section text.
It is expected for a GCC compiler version to be listed due to the use of libstdc++ in all
MongoDB binaries."""

MongoDB binaries.
"""
if (match := cls.gcc_version_regexp.search(raw_elf_section)) is not None:
return match.group(1).decode()

Expand All @@ -98,8 +99,8 @@ def parse_clang_version(cls, raw_elf_section: bytes, /) -> typing.Optional[str]:
@classmethod
def parse_libstdcxx_python_home(cls, gcc_version: str, /) -> typing.Optional[pathlib.Path]:
"""Return the /opt/mongodbtoolchain/vN/share/gcc-X.Y.Z/python directory associated with a
particular GCC compiler version."""

particular GCC compiler version.
"""
if gcc_version.endswith(" 8.5.0"):
return pathlib.Path("/opt/mongodbtoolchain/v3/share/gcc-8.5.0/python")

Expand Down
3 changes: 0 additions & 3 deletions gdbmongo/interaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ def _import_libstdcxx_printers(executable: str, /, *, register_libstdcxx_printer
MongoDB toolchain the executable was compiled with. Register the imported module on sys.modules
and optionally register the pretty printers with GDB itself, if requested.
"""

detector = ToolchainVersionDetector(executable)
toolchain_info = detector.detect()

Expand All @@ -49,7 +48,6 @@ def register_printers(*, essentials: bool = True, stdlib: bool = False, abseil:
The pretty printer collections other than gdbmongo-essentials are defaulted to off to avoid
conflicting with the pretty printers defined in the mongodb/mongo repository.
"""

if essentials:
# It would be weird to not register these pretty printers given the whole purpose of the
# gdbmongo package, but a user can always choose to disable them explicitly so we may as
Expand All @@ -76,7 +74,6 @@ def on_user_at_prompt() -> None:
"""Import the libstdc++ GDB pretty printers when either the `attach <pid>` or
`core-file <pathname>` commands are run in GDB.
"""

if (executable := gdb.selected_inferior().progspace.filename) is None:
# The `attach` command would have filled in the filename so we only need to check if
# a core dump has been loaded with the executable file also being loaded.
Expand Down
4 changes: 2 additions & 2 deletions gdbmongo/lock_manager_printer.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ def gdb_lookup_value(symbol_name: str, /) -> typing.Optional[gdb.Value]:

class ServiceContextDecorationMixin(typing.Protocol):
"""Class to add support for constructing from the global ServiceContext if the subclass already
supports constructing from a ServiceContext explicitly."""
supports constructing from a ServiceContext explicitly.
"""

Decoration = typing.TypeVar("Decoration", bound="ServiceContextDecorationMixin")

Expand Down Expand Up @@ -89,7 +90,6 @@ def lookup_resource_name(self, res_id: gdb.Value, /) -> typing.Optional[gdb.Valu
"""Return a gdb.Value containing the database or collection namespace string of the
resource.
"""

iterator = stdlib_printers.StdMapPrinter("std::map", self.resources).children()
for ((_, iter_res_id), (_, iter_nss_set)) in zip(iterator, iterator):
if iter_res_id == res_id:
Expand Down
1 change: 0 additions & 1 deletion gdbmongo/stdlib_printers_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ def resolve_import(toolchain_info: gdbmongo.detect_toolchain.ToolchainInfo,
the 0-argument function will NOT have registered the pretty printers with GDB itself. The caller
must take care to call register_libstdcxx_printers() on the returned module object.
"""

if (libstdcxx_python_home := toolchain_info.libstdcxx_python_home) is None:
raise ValueError("Unable to import libstdc++ GDB pretty printers")

Expand Down
1 change: 1 addition & 0 deletions stubs/gdb/_type.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import typing

class TypeCode(enum.IntEnum):
"""https://sourceware.org/git/?p=binutils-gdb.git;a=blob;f=gdb/gdbtypes.h;hb=refs/tags/gdb-8.3.1-release#l90"""

TYPE_CODE_BITSTRING = -1
TYPE_CODE_PTR = 1
TYPE_CODE_ARRAY = 2
Expand Down
3 changes: 2 additions & 1 deletion stubs/gdb/printing.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
###
"""https://sourceware.org/gdb/onlinedocs/gdb/Pretty-Printing-API.html
https://sourceware.org/gdb/onlinedocs/gdb/Writing-a-Pretty_002dPrinter.html
https://sourceware.org/gdb/onlinedocs/gdb/gdb_002eprinting.html"""
https://sourceware.org/gdb/onlinedocs/gdb/gdb_002eprinting.html
"""

import typing

Expand Down
3 changes: 2 additions & 1 deletion tests/test_formatting.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ def find_pyfiles() -> typing.Iterator[pathlib.Path]:
def run_yapf(fix: bool) -> bool:
"""Return True if YAPF reports no further changes are needed, and return False otherwise.
This function always returns True when fix == True."""
This function always returns True when fix == True.
"""
# We import the module here to suppress the PendingDeprecationWarning.
# pylint: disable-next=import-outside-toplevel
import yapf
Expand Down
2 changes: 0 additions & 2 deletions tests/test_stdlib_printers.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ def test_can_load_module_from_toolchain(toolchain_info: ToolchainInfo) -> None:
"""Check that the gdb.libstdcxx.v6 package can be loaded without error for the corresponding
version of the MongoDB toolchain.
"""

(module, _register_module) = resolve_import(toolchain_info)
assert module.register_libstdcxx_printers is not None

Expand All @@ -72,7 +71,6 @@ def test_can_import_module_after_registering(self) -> None:
"""Check that the gdb.libstdcxx.v6 module is only available to import after the returned
register_module() function has been called.
"""

(_module, register_module) = resolve_import(self.toolchain_info)
assert "gdb.libstdcxx.v6" not in sys.modules
assert "gdb.libstdcxx.v6.printers" not in sys.modules
Expand Down

0 comments on commit 25fc602

Please sign in to comment.