From 129e86a4ac33ac7f9de85f12e83bb6760918cbae Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Tue, 1 Oct 2024 23:07:07 -0400 Subject: [PATCH] pyproject.toml: pyright: ignore reportPrivateUsage Our code does not follow the convention of treating identifiers starting with an underscore as private. For instance, the `bt2` module exposes types like `_EventMessageConst`. Even though the user is not expected to create objects of that type, they can still use the type in a type check like: if type(msg) is bt2._EventMessageConst: That produces a `reportPrivateUsage` in pyright / pylance. Disable that check to get rid of a lot of false positives. Change-Id: I78a19653aafb923d3e429b9b321cb1f87372c83e Signed-off-by: Simon Marchi Reviewed-on: https://review.lttng.org/c/babeltrace/+/13307 Reviewed-by: Philippe Proulx Tested-by: jenkins --- pyproject.toml | 3 +++ tests/utils/python/normand.py | 20 ++++++++------------ tests/utils/python/tjson.py | 4 ++-- 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index fb033ec7..9ceb2032 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -26,3 +26,6 @@ extend_skip_glob = [ "tests/utils/python/typing/typing.py", ] length_sort = true + +[tool.pyright] +reportPrivateUsage = false diff --git a/tests/utils/python/normand.py b/tests/utils/python/normand.py index 4c7063d4..06d9570a 100644 --- a/tests/utils/python/normand.py +++ b/tests/utils/python/normand.py @@ -109,8 +109,7 @@ class _ScalarItem(_Item): # Returns the size, in bytes, of this item. @property @abc.abstractmethod - def size(self) -> int: - ... + def size(self) -> int: ... # A repeatable item. @@ -618,7 +617,7 @@ class ParseError(RuntimeError): def _add_msg(self, msg: str, text_loc: TextLocation): self._msgs.append( - ParseErrorMessage._create( # pyright: ignore[reportPrivateUsage] + ParseErrorMessage._create( msg, text_loc ) ) @@ -633,12 +632,12 @@ class ParseError(RuntimeError): # Raises a parsing error, forwarding the parameters to the constructor. def _raise_error(msg: str, text_loc: TextLocation) -> NoReturn: - raise ParseError._create(msg, text_loc) # pyright: ignore[reportPrivateUsage] + raise ParseError._create(msg, text_loc) # Adds a message to the parsing error `exc`. def _add_error_msg(exc: ParseError, msg: str, text_loc: TextLocation): - exc._add_msg(msg, text_loc) # pyright: ignore[reportPrivateUsage] + exc._add_msg(msg, text_loc) # Appends a message to the parsing error `exc` and reraises it. @@ -761,7 +760,7 @@ class _Parser: # Current text location. @property def _text_loc(self): - return TextLocation._create( # pyright: ignore[reportPrivateUsage] + return TextLocation._create( self._line_no, self._col_no ) @@ -2105,8 +2104,7 @@ class _NodeVisitor(ast.NodeVisitor): self._parent_is_call = False @abc.abstractmethod - def _visit_name(self, name: str): - ... + def _visit_name(self, name: str): ... # Expression validator: validates that all the names within the @@ -2607,7 +2605,7 @@ class _Gen: # Process the contained group init_data_size = len(self._data) parse_error_msg = ( - ParseErrorMessage._create( # pyright: ignore[reportPrivateUsage] + ParseErrorMessage._create( parse_error_msg_text, item.text_loc ) ) @@ -2833,9 +2831,7 @@ def parse( init_offset, init_byte_order, ) - return ParseResult._create( # pyright: ignore[reportPrivateUsage] - gen.data, gen.variables, gen.labels, gen.offset, gen.bo - ) + return ParseResult._create(gen.data, gen.variables, gen.labels, gen.offset, gen.bo) # Raises a command-line error with the message `msg`. diff --git a/tests/utils/python/tjson.py b/tests/utils/python/tjson.py index 59a5a1c4..55e8873a 100644 --- a/tests/utils/python/tjson.py +++ b/tests/utils/python/tjson.py @@ -221,8 +221,8 @@ def _check_type(val: Val, expected_type: Type[Val]): raise TypeError( "`{}`: expecting {} value, got {}".format( val.path, - expected_type._name, # pyright: ignore [reportPrivateUsage] - type(val)._name, # pyright: ignore [reportPrivateUsage] + expected_type._name, + type(val)._name, ) ) -- 2.34.1