Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Stubtest: verify stub methods or properties are decorated with@final if they are decorated with@final at runtime#14951

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
sobolevn merged 7 commits intopython:masterfromAlexWaygood:stubtest-final-methods
Mar 24, 2023
Merged
Show file tree
Hide file tree
Changes from1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
PrevPrevious commit
NextNext commit
Blacken, plus more comments
  • Loading branch information
@AlexWaygood
AlexWaygood committedMar 24, 2023
commiteb5d0e150aaba036b35fc0322806ca93e14ba3ea
14 changes: 7 additions & 7 deletionsmypy/stubtest.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1065,6 +1065,8 @@ def verify_overloadedfuncdef(
for message in _verify_static_class_methods(stub, runtime, static_runtime, object_path):
yield Error(object_path, "is inconsistent, " + message, stub, runtime)

# TODO: Should call _verify_final_method here, but it crashes stubtest: see #14950

signature = safe_inspect_signature(runtime)
if not signature:
return
Expand DownExpand Up@@ -1154,15 +1156,13 @@ def _verify_abstract_status(stub: nodes.FuncDef, runtime: Any) -> Iterator[str]:
yield f"is inconsistent, runtime {item_type} is abstract but stub is not"


def _verify_final_method(stub: nodes.FuncDef, runtime: Any, static_runtime: MaybeMissing[Any]) -> Iterator[str]:
def _verify_final_method(
stub: nodes.FuncDef, runtime: Any, static_runtime: MaybeMissing[Any]
) -> Iterator[str]:
if stub.is_final:
return
if (
getattr(runtime, "__final__", False)
or (
static_runtime is not MISSING
and getattr(static_runtime, "__final__", False)
)
if getattr(runtime, "__final__", False) or (
static_runtime is not MISSING and getattr(static_runtime, "__final__", False)
):
yield "is decorated with @final at runtime, but not in the stub"

Expand Down
18 changes: 18 additions & 0 deletionsmypy/test/teststubtest.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1364,6 +1364,24 @@ def foo(self): return 42
""",
error="K.foo",
)
# This test wouldn't pass,
# because the runtime can't set __final__ on instances of builtins.property,
# so stubtest has non way of knowing that the runtime was decorated with @final:
#
# yield Case(
# stub="""
# class K2:
# @property
# def foo(self) -> int: ...
# """,
# runtime="""
# class K2:
# @final
# @property
# def foo(self): return 42
# """,
# error="K2.foo",
# )
yield Case(
stub="""
class L:
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp