Skip to content
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

Closed
pyrocat101 opened this issue Apr 11, 2016 · 43 comments · Fixed by #13409 or pypa/twine#927
Closed

Decorated property not supported #1362

pyrocat101 opened this issue Apr 11, 2016 · 43 comments · Fixed by #13409 or pypa/twine#927
Labels
false-positive mypy gave an error on correct code feature priority-1-normal topic-descriptors Properties, class vs. instance attributes

Comments

@pyrocat101
Copy link

class Foo(object):
    @property
    @some_decorator
    def foo(self):
        ...

is valid in Python 2, but MyPy complains Decorated property not supported.
Adding type: ignore does not ignore the error.

@gvanrossum
Copy link
Member

Good news: if you put the # type: ignore on the @property line it's silent.

@nullp0tr
Copy link

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
Copy link
Member

Since properties are common in Python, that's not something to be concerned about.

@nullp0tr
Copy link

Thanks for the clarification.

@OJFord
Copy link

OJFord commented Nov 13, 2018

Good news: if you put the # type: ignore on the @property line it's silent.

Note it appears to need to be on the outer decorator, so if you have the opposite order to OP:

@some_decorator
@property
def foo

then it should be on the @some_decorator line.

@gvanrossum
Copy link
Member

gvanrossum commented Nov 13, 2018 via email

CumulonimbusCalvus added a commit to QuTech-Delft/qtt that referenced this issue Jun 26, 2019
* [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.
jaraco added a commit to pypa/twine that referenced this issue Nov 17, 2019
Co-Authored-By: Brian Rutledge <bhrutledge@gmail.com>
rytilahti added a commit to rytilahti/python-miio that referenced this issue Aug 13, 2022
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.
ilevkivskyi added a commit that referenced this issue Aug 14, 2022
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 <>
@leycec
Copy link

leycec commented Sep 17, 2022

Gah! How is this possibly still an issue in late 2022? It's literally been eight years. Sad panda is sad.

so sad panda

@graingert
Copy link
Contributor

graingert commented Sep 17, 2022

Gah! How is this possibly still an issue in late 2022? It's literally been eight years. Sad panda is sad.

so sad panda so sad panda

Afaik it's fixed in the master branch

@bew
Copy link

bew commented Sep 19, 2022

Any idea when will be the next release with this change?

@hauntsaninja
Copy link
Collaborator

Soon, follow #13385

@analog-cbarber
Copy link
Contributor

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
Copy link

bew commented Oct 20, 2022

(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): ...

?

@analog-cbarber
Copy link
Contributor

That would not be correct. My decorator takes a property and returns a property. It is decorating the property and not the function.

@leycec
Copy link

leycec commented 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.,

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 # type: ignore. Through ignorance, we pretend mypy is sane.

@OJFord
Copy link

OJFord commented 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.

Sygus pushed a commit to netzob/netzob that referenced this issue Dec 29, 2022
-- Carried out under contract n°1100036530 for ANSSI --
Sygus pushed a commit to netzob/netzob that referenced this issue Dec 30, 2022
sqlalchemy-bot pushed a commit to sqlalchemy/sqlalchemy that referenced this issue Jan 12, 2023
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
garrison added a commit to qiskit-community/prototype-qrao that referenced this issue Feb 26, 2023
@samskiter
Copy link

Soon, follow #13385

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)

@hhartzer
Copy link

Could someone explain why this is closed? It still seems to be an issue.

@python python locked as resolved and limited conversation to collaborators Mar 12, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
false-positive mypy gave an error on correct code feature priority-1-normal topic-descriptors Properties, class vs. instance attributes
Projects
None yet