Skip to content

Commit

Permalink
use new allowedUntypedLibraries basedpyright setting
Browse files Browse the repository at this point in the history
  • Loading branch information
DetachHead committed Feb 10, 2025
1 parent be57ebc commit 29b6477
Show file tree
Hide file tree
Showing 16 changed files with 36 additions and 71 deletions.
8 changes: 5 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,12 @@ enable_assertion_pass_hook = true
[tool.basedpyright]
ignore = ["pw"]
pythonVersion = "3.9"
reportMissingTypeStubs = false # https://github.com/robotframework/robotframework/issues/4822
allowedUntypedLibraries = [
'robot', # https://github.com/robotframework/robotframework/issues/4822
]
reportImplicitStringConcatenation = false # handled by ruff
reportUnusedImport = false # covered by ruff (has quickfix)
reportUnusedVariable = false # covered by ruff (has quickfix)
reportUnusedImport = false # covered by ruff (has quickfix)
reportUnusedVariable = false # covered by ruff (has quickfix)

[tool.ruff]
unsafe-fixes = true
Expand Down
22 changes: 7 additions & 15 deletions pytest_robotframework/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@
from robot.running.context import _ExecutionContext # pyright:ignore[reportPrivateUsage]
from robot.running.librarykeywordrunner import LibraryKeywordRunner
from robot.running.statusreporter import ExecutionStatus, HandlerExecutionFailed, StatusReporter
from robot.utils import (
getshortdoc, # pyright:ignore[reportUnknownVariableType]
printable_name, # pyright:ignore[reportUnknownVariableType]
)
from robot.utils import getshortdoc, printable_name
from robot.utils.error import ErrorDetails
from typing_extensions import Literal, Never, TypeAlias, deprecated, override

Expand Down Expand Up @@ -75,9 +72,7 @@ def import_resource(path: Path | str) -> None:
to import libraries, use a regular python import"""
if execution_context():
BuiltIn().import_resource( # pyright:ignore[reportUnknownMemberType]
escape_robot_str(str(path))
)
BuiltIn().import_resource(escape_robot_str(str(path)))
else:
_resources.append(Path(path))

Expand All @@ -104,7 +99,7 @@ def _get_failure(self, *args: Never, **kwargs: Never):
return exc_value
if isinstance(exc_value, DataError):
msg = exc_value.message
context.fail(msg) # pyright:ignore[reportUnknownMemberType]
context.fail(msg)
return ExecutionFailed(msg, syntax=exc_value.syntax)

tb = None
Expand Down Expand Up @@ -145,11 +140,11 @@ def _get_failure(self, *args: Never, **kwargs: Never):
# therefore has already been logged by its status reporter
is_nested_status_reporter_failure = len(_get_status_reporter_failures(exc_value)) > 1
if failure.skip:
context.skip(error.message) # pyright:ignore[reportUnknownMemberType]
context.skip(error.message)
elif not is_nested_status_reporter_failure:
context.fail(error.message) # pyright:ignore[reportUnknownMemberType]
context.fail(error.message)
if not is_nested_status_reporter_failure and error.traceback:
context.debug(error.traceback) # pyright:ignore[reportUnknownMemberType]
context.debug(error.traceback)
return failure


Expand Down Expand Up @@ -288,10 +283,7 @@ def truncate(arg: object) -> str:
context=context,
suppress=suppress,
implementation=cast(
LibraryKeywordRunner,
context.get_runner( # pyright:ignore[reportUnknownMemberType]
keyword_name
),
LibraryKeywordRunner, context.get_runner(keyword_name)
).keyword.bind(data),
)
)
Expand Down
12 changes: 6 additions & 6 deletions pytest_robotframework/_internal/pytest/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
from robot.libraries.BuiltIn import BuiltIn
from robot.output import LOGGER
from robot.rebot import Rebot
from robot.result.resultbuilder import ExecutionResult # pyright:ignore[reportUnknownVariableType]
from robot.result.resultbuilder import ExecutionResult
from robot.run import RobotFramework, RobotSettings
from robot.utils.error import ErrorDetails
from typing_extensions import TYPE_CHECKING, Callable, Generator, Mapping, cast
Expand Down Expand Up @@ -253,7 +253,7 @@ def _get_robot_args(session: Session) -> RobotOptions:
options,
cast(
RobotOptions,
RobotFramework().parse_arguments( # pyright:ignore[reportUnknownMemberType]
RobotFramework().parse_arguments(
# i don't think this is actually used here, but we send it the correct paths
# just to be safe
_get_pytest_collection_paths(session)
Expand Down Expand Up @@ -287,7 +287,7 @@ def _run_robot(session: Session, robot_options: InternalRobotOptions):
# LOGGER is needed for log_file listener methods to prevent logger from deactivating after
# the test is over
with LOGGER:
exit_code = robot.main( # pyright:ignore[reportUnknownMemberType]
exit_code = robot.main(
_get_pytest_collection_paths(session),
# needed because PythonParser.visit_init creates an empty suite
**robot_options,
Expand Down Expand Up @@ -458,7 +458,7 @@ def redirector(file: IO[str]) -> contextlib._RedirectStream[IO[str]]: # pyright
for output in outputs:
_ = cast(
int,
rebot.main( # pyright:ignore[reportUnknownMemberType]
rebot.main(
[output], output=output, name=merged_suite_name, stdout=None
),
)
Expand Down Expand Up @@ -494,7 +494,7 @@ def redirector(file: IO[str]) -> contextlib._RedirectStream[IO[str]]: # pyright
)
rebot_options["loglevel"] = f"TRACE:{default_log_level}"

_ = rebot.main( # pyright:ignore[reportUnknownVariableType,reportUnknownMemberType]
_ = rebot.main( # pyright:ignore[reportUnknownVariableType]
outputs,
# merge is deliberately specified here instead of in the merged dict because
# it should never be overwritten
Expand Down Expand Up @@ -591,7 +591,7 @@ def pytest_runtest_setup(item: Item) -> HookWrapperResult:
# section and resources should be imported with `Resource` in the `*** Settings***` section
builtin = BuiltIn()
for key, value in _suite_variables[item.path].items():
builtin.set_suite_variable( # pyright:ignore[reportUnknownMemberType]
builtin.set_suite_variable(
r"${" + key + "}", escape_robot_str(value) if isinstance(value, str) else value
)
del _suite_variables[item.path]
Expand Down
10 changes: 3 additions & 7 deletions pytest_robotframework/_internal/pytest/robot_file_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,7 @@ def _check_skipped() -> Iterator[None]:
def _run_keyword(self, keyword: model.Keyword | None):
if keyword and keyword.name is not None and keyword.name.lower() != "none":
with self._check_skipped():
BuiltIn().run_keyword( # pyright:ignore[reportUnknownMemberType]
keyword.name, *keyword.args
)
BuiltIn().run_keyword(keyword.name, *keyword.args)

@override
def setup(self):
Expand All @@ -143,17 +141,15 @@ def runtest(self):
if robot_6:
with check_skipped:
# pyright is only run when robot 7 is installed
BodyRunner( # pyright:ignore[reportUnknownMemberType,reportCallIssue]
BodyRunner( # pyright:ignore[reportCallIssue]
context=context, templated=bool(test.template)
).run(self.stash[original_body_key])
else:
wrapped_body = test.body
test.body = self.stash[original_body_key]
try:
with check_skipped:
BodyRunner( # pyright:ignore[reportUnknownMemberType]
context=context, templated=bool(test.template)
).run(
BodyRunner(context=context, templated=bool(test.template)).run(
data=test,
result=context.test, # pyright:ignore[reportUnknownMemberType]
)
Expand Down
2 changes: 1 addition & 1 deletion pytest_robotframework/_internal/pytest/xdist_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
def get_xdist():
try:
# xdist may not be installed
import xdist # noqa: PLC0415
import xdist # noqa: PLC0415 # pyright:ignore[reportMissingTypeStubs]
except ModuleNotFoundError:
return None
return xdist
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
from _pytest import runner
from _pytest.python import PyobjMixin
from ansi2html import Ansi2HTMLConverter
from basedtyping import Function, P, T
from pluggy import HookCaller, HookImpl
from pluggy._hooks import _SubsetHookCaller # pyright:ignore[reportPrivateUsage]
from pytest import Class, Function as PytestFunction, Item, Module, Session, StashKey
Expand Down Expand Up @@ -62,6 +61,7 @@
from types import ModuleType

from _pytest.nodes import Node
from basedtyping import Function, P, T
from robot.running.builder.settings import TestDefaults
from robot.running.context import _ExecutionContext # pyright:ignore[reportPrivateUsage]

Expand Down Expand Up @@ -623,12 +623,9 @@ def _runner_for( # pyright:ignore[reportUnusedFunction] # noqa: PLR0917
"""use the original function instead of the `@keyword` wrapped one"""
original_function: Function | None = getattr(handler, _keyword_original_function_attr, None)
wrapped_function = _hide_already_raised_exception_from_robot_log(
cast(
Function,
_bound_method(handler.__self__, original_function)
if original_function is not None and isinstance(handler, MethodType)
else (original_function or handler),
)
_bound_method(handler.__self__, original_function)
if original_function is not None and isinstance(handler, MethodType)
else (original_function or handler)
)
return old_method(self, context, wrapped_function, positional, named)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@


def test_foo():
BuiltIn().run_keyword("bar") # pyright:ignore[reportUnknownMemberType]
BuiltIn().run_keyword("bar")
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,4 @@


def test_foo():
assert (
BuiltIn().get_variable_value("$foo") # pyright:ignore[reportUnknownMemberType]
== "bar"
)
assert BuiltIn().get_variable_value("$foo") == "bar"
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,4 @@


def test_foo():
assert (
BuiltIn().get_variable_value("$foo") # pyright:ignore[reportUnknownMemberType]
is None
)
assert BuiltIn().get_variable_value("$foo") is None
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,4 @@


def test_foo():
assert (
BuiltIn().get_variable_value("$foo") # pyright:ignore[reportUnknownMemberType]
== "bar"
)
assert BuiltIn().get_variable_value("$foo") == "bar"
2 changes: 1 addition & 1 deletion tests/fixtures/test_python/test_set_log_level.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@


def test_asdf():
BuiltIn().set_log_level("DEBUG") # pyright:ignore[reportUnknownMemberType]
BuiltIn().set_log_level("DEBUG")
debug("hello???")
4 changes: 1 addition & 3 deletions tests/fixtures/test_python/test_suite_variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,4 @@


def test_asdf():
assert BuiltIn().get_variable_value( # pyright:ignore[reportUnknownMemberType]
"$foo"
) == {"bar": ""}
assert BuiltIn().get_variable_value("$foo") == {"bar": ""}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,4 @@


def test_asdf():
assert (
BuiltIn().get_variable_value("$foo") # pyright:ignore[reportUnknownMemberType]
== "bar\\baz"
)
assert BuiltIn().get_variable_value("$foo") == "bar\\baz"
4 changes: 1 addition & 3 deletions tests/fixtures/test_python/test_variables_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,4 @@


def test_asdf():
assert BuiltIn().get_variable_value( # pyright:ignore[reportUnknownMemberType]
"$foo"
) == ["bar", "baz"]
assert BuiltIn().get_variable_value("$foo") == ["bar", "baz"]
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,4 @@


def test_asdf():
assert (
BuiltIn().get_variable_value("$foo") # pyright:ignore[reportUnknownMemberType]
== "bar"
)
assert BuiltIn().get_variable_value("$foo") == "bar"
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,4 @@


def test_func():
assert (
BuiltIn().get_variable_value("$foo") # pyright:ignore[reportUnknownMemberType]
is None
)
assert BuiltIn().get_variable_value("$foo") is None

0 comments on commit 29b6477

Please sign in to comment.