-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Decorated property not supported #1362
Comments
Good news: if you put the |
A bit off topic, but I came across this warning today and it made me wonder about something. I have a BLE Connection class, and each instance has the attributes characteristics and services, which are implemented with the @Property decorator so that it can actually fetch them a new every time without assigning a lambda or making them a method. Fetching can raise an exception though, and I'm wondering how normal is it that something like "a = b.attribute" can raise an exception that can't be just avoided by rearranging the code like from a NameError or a SyntaxError? |
Since properties are common in Python, that's not something to be concerned about. |
Thanks for the clarification. |
Note it appears to need to be on the outer decorator, so if you have the opposite order to OP:
then it should be on the |
Correct, messages related to a function (or, sometimes, its arguments)
always appear on the line of the first decorator, if there is one,
otherwise on the linke containing 'def'. (I consider this a slight flaw, as
occasionally it makes it hard to find the root cause for an error message.)
The rule "put the '# type: ignore' on the line where the error appears" is
pretty simple to remember though.
|
* [DEM-943] Moved number of averages to scope reader acquire. * [DEM-943] Updated processing example. * [DEM-943] Added channel limit setter. * [DEM-943] Added combined example. Changed to old processing. * [DEM-943] Added segment scope reader tests. * [DEM-943] Removed needed ScopeReader name in scans. * [DEM-943] Unit scope reader. * [DEM-943] Updated stimulus functions. * [DEM-943] Changed default arguments. * [DEM-943] Resolved review comments. * [DEM-943] Changed output marker and sweep initial waiting time. * [DEM-943] Decorated property not supported (python/mypy#1362). * [DEM-943] Enable external clock UHFLI. * [DEM-943] Map misses setting first channel. * [DEM-943] Data is one element longer? * [DEM-943] Addressed review comments.
Co-Authored-By: Brian Rutledge <bhrutledge@gmail.com>
This fixes "Decorated property not supported" errors for the time being without hopefully many downsides. The impact is hard to measure as the list of misc errors is not to be found. This should be revisited if/when python/mypy#1362 gets solved.
Fixes #1362 I delete the old cryptic error message and instead: * Enable the situations that we can already handle (cover 95% of what was discussed in the issue) * For the rest give more precise error messages Co-authored-by: graingert <>
Any idea when will be the next release with this change? |
Soon, follow #13385 |
So now there is just a new useless error. Now I get "Decorators on top of @Property are not supported". What purpose does this error serve? |
(edit: well, looks like that's not wanted `¯\_(ツ)_/¯`, I tried)The comment I tried to suggest: Try changing @your_decorator
@property
def foo(self): ... to @property
@your_decorator
def foo(self): ... ? |
That would not be correct. My decorator takes a property and returns a property. It is decorating the property and not the function. |
Yup. @beartype transparently supports both modalities, too – including direct decoration of high-level property getters, setters, and deleters as well as of lower-level methods subsequently decorated as property getters, setters, and deleters. Decoration order is irrelevant (as it should be): e.g., from beartype import beartype
class FunWithHungryBears(object):
# This is fine.
@beartype
@property
def feed_bear_garbage() -> str:
return 'Bear responds by tearing apart garbage.'
# This is fine, too.
@property
@beartype
def throw_salmon_at_bear() -> str:
return 'Bear responds by opening spittle-flecked muzzle.' Thank Guido for |
@bew Your suggestion was semantically different - imagine mypy didn't work with list arguments for some reason, 'try using a set instead' wouldn't really be a solution. |
-- Carried out under contract n°1100036530 for ANSSI --
This decorator is no longer necessary as of Mypy 0.981 [1]. In current mypy versions, we require direct use of `@property` for return types of these methods to be recognized [1] python/mypy#1362 Change-Id: Ibc36083dec854c5f9140a9b621e9bf9d5bb4fb61
Still not fixed and appears as a gotcha in the pydantic docs: https://docs.pydantic.dev/2.0/usage/computed_fields/ (On mypy v 1.5.1) |
Could someone explain why this is closed? It still seems to be an issue. |
is valid in Python 2, but MyPy complains
Decorated property not supported
.Adding
type: ignore
does not ignore the error.The text was updated successfully, but these errors were encountered: