Skip to content

Conversation

@stroxler
Copy link
Contributor

@stroxler stroxler commented Oct 13, 2022

As per discussion in
https://mail.python.org/archives/list/[email protected]/thread/TOIYZ3SNPBJZDBRU3ZSBREXV2NNHF4KW/, we believe this is a good feature to have (as best-effort: it will not work in all cases if the user does not understand decorator implementations enough to get the right order, and it will alwasys fail if a decorator output does not support dynamic attributes).

We decided to support this for two reasons:

  • it was a direct request from the overrides library owner
  • typing_extensions.final has similar behavior

Tests:

cd src
python -m unittest test_typing_extensions.py

Lints:

flake8
flake8 --config=.flake8-tests src/test_typing_extensions.py

I'll edit PEP 698 to cover this behavior this week, but I wanted to get feedback here and back-port to pyre_extensions first so that we can have the runtime behavior linked in the reference implementation.

I tried to include a test of a decorator with __slots__, but I don't know descriptors that well and got stuck. I can add that if we really want it but wasn't sure I wanted to spend the time otherwise. I would guess that most of the time when the runtime behavior fails it will be due to out-of-order decorators rather than output types that have fixed slots, so my static method examples seem more useful as edge-case documentation.

As per discussion in
https://mail.python.org/archives/list/[email protected]/thread/TOIYZ3SNPBJZDBRU3ZSBREXV2NNHF4KW/,
we believe this is a good feature to have (as best-effort: it will not
work in all cases if the user does not understand decorator implementations
enough to get the right order, and it will alwasys fail if a decorator
output does not support dynamic attributes).

We decided to support this for two reasons:
- it was a direct request from the `overrides` library owner
- `typing_extensions.final` has similar behavior

Tests:
```
cd src
python -m unittest test_typing_extensions.py
```

Lints:
```
flake8
flake8 --config=.flake8-tests src/test_typing_extensions.py
```
@stroxler stroxler changed the title Add __override__ attribute to @override Add __override__ attribute to @override (PEP 698) Oct 13, 2022
@stroxler
Copy link
Contributor Author

cc @JelleZijlstra

@JelleZijlstra JelleZijlstra self-requested a review October 17, 2022 21:29
@JelleZijlstra JelleZijlstra merged commit 6e72c09 into python:main Oct 20, 2022
stroxler added a commit to stroxler/peps that referenced this pull request Oct 28, 2022
We decided to add this for two reasons:

- It was specifically requested by the author of the `overrides`
  library, because there there are some handy runtime uses
  of override information (such as propagating docstrings, which
  we highlight as a concrete example)
- We realized that we actually added `__final__` to
  `@typing.final` in spite of it not being specified in PEP 591,
  which we felt strongly suggests that even if we omit it we
  would later change our minds.

This runtime behavior is currently implemented in typing_extensions
(see python/typing_extensions#86) as well
as pyre_extensions.
JelleZijlstra pushed a commit to python/peps that referenced this pull request Oct 28, 2022
We decided to add this for two reasons:

- It was specifically requested by the author of the `overrides`
  library, because there there are some handy runtime uses
  of override information (such as propagating docstrings, which
  we highlight as a concrete example)
- We realized that we actually added `__final__` to
  `@typing.final` in spite of it not being specified in PEP 591,
  which we felt strongly suggests that even if we omit it we
  would later change our minds.

This runtime behavior is currently implemented in typing_extensions
(see python/typing_extensions#86) as well
as pyre_extensions.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants