Skip to content
Merged
Changes from 1 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
Prev Previous commit
Next Next commit
fix run
Signed-off-by: Ashwin Naren <arihant2math@gmail.com>
  • Loading branch information
arihant2math committed Apr 18, 2025
commit dc3a7ebf478aa18912ece9c115e2b911c6523174
75 changes: 38 additions & 37 deletions Lib/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -3687,43 +3687,44 @@ def decorator(cls_or_fn):
return cls_or_fn
return decorator


type _Func = Callable[..., Any]


def override[F: _Func](method: F, /) -> F:
"""Indicate that a method is intended to override a method in a base class.

Usage::

class Base:
def method(self) -> None:
pass

class Child(Base):
@override
def method(self) -> None:
super().method()

When this decorator is applied to a method, the type checker will
validate that it overrides a method or attribute with the same name on a
base class. This helps prevent bugs that may occur when a base class is
changed without an equivalent change to a child class.

There is no runtime checking of this property. The decorator attempts to
set the ``__override__`` attribute to ``True`` on the decorated object to
allow runtime introspection.

See PEP 698 for details.
"""
try:
method.__override__ = True
except (AttributeError, TypeError):
# Skip the attribute silently if it is not writable.
# AttributeError happens if the object has __slots__ or a
# read-only property, TypeError if it's a builtin class.
pass
return method
# TODO: RUSTPYTHON

# type _Func = Callable[..., Any]


# def override[F: _Func](method: F, /) -> F:
# """Indicate that a method is intended to override a method in a base class.
#
# Usage::
#
# class Base:
# def method(self) -> None:
# pass
#
# class Child(Base):
# @override
# def method(self) -> None:
# super().method()
#
# When this decorator is applied to a method, the type checker will
# validate that it overrides a method or attribute with the same name on a
# base class. This helps prevent bugs that may occur when a base class is
# changed without an equivalent change to a child class.
#
# There is no runtime checking of this property. The decorator attempts to
# set the ``__override__`` attribute to ``True`` on the decorated object to
# allow runtime introspection.
#
# See PEP 698 for details.
# """
# try:
# method.__override__ = True
# except (AttributeError, TypeError):
# # Skip the attribute silently if it is not writable.
# # AttributeError happens if the object has __slots__ or a
# # read-only property, TypeError if it's a builtin class.
# pass
# return method


def is_protocol(tp: type, /) -> bool:
Expand Down