You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Good news: if you put the # type: ignore on the @property line it's silent.
Reacted by Maciej Olko, Andrew Yurisich, Jan Freyberg, Maurício Eduardo Loschi Batista, Aziz Alto, MercyPrasanna, Donghyun (Anthony) Kim, Eero Ruohola, Stefano Pettini, Boris Pavlovic and 8 more
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?
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.
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.,
frombeartypeimportbeartypeclassFunWithHungryBears(object):
# This is fine.@beartype@propertydeffeed_bear_garbage() ->str:
return'Bear responds by tearing apart garbage.'# This is fine, too.@property@beartypedefthrow_salmon_at_bear() ->str:
return'Bear responds by opening spittle-flecked muzzle.'
Thank Guido for # type: ignore. Through ignorance, we pretend mypy is sane.
@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.
Activity
gvanrossum commentedon Apr 11, 2016
Good news: if you put the
# type: ignoreon the@propertyline it's silent.nullp0tr commentedon Feb 19, 2018
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?
gvanrossum commentedon Feb 19, 2018
Since properties are common in Python, that's not something to be concerned about.
nullp0tr commentedon Feb 20, 2018
Thanks for the clarification.
OJFord commentedon Nov 13, 2018
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
@some_decoratorline.gvanrossum commentedon Nov 13, 2018
[DEM-943] Decorated property not supported (python/mypy#1362).
[DEM-943] Decorated property not supported (python/mypy#1362).
59 remaining items
hauntsaninja commentedon Sep 19, 2022
Soon, follow #13385
analog-cbarber commentedon Oct 20, 2022
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?
bew commentedon Oct 20, 2022
(edit: well, looks like that's not wanted `¯\_(ツ)_/¯`, I tried)
The comment I tried to suggest:
Try changing
to
?
analog-cbarber commentedon Oct 20, 2022
That would not be correct. My decorator takes a property and returns a property. It is decorating the property and not the function.
leycec commentedon Oct 21, 2022
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.,
Thank Guido for
# type: ignore. Through ignorance, we pretend mypy is sane.OJFord commentedon Oct 21, 2022
@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.
mypy: silent property setter error (see python/mypy#1362)
mypy: silent property setter error (see python/mypy#1362)
replace @decorated_property decorator
Bump mypy version
samskiter commentedon Dec 9, 2023
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)
Ignore mypy error
Ignore mypy error
hhartzer commentedon Mar 12, 2024
Could someone explain why this is closed? It still seems to be an issue.