Skip to content

Decorated property not supported #1362

Description

@pyrocat101
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.

Activity

  1. gvanrossum commented on Apr 11, 2016

    @gvanrossum
    Member

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

  2. added this to the milestone on Apr 11, 2016
  3. removed this from the milestone on Mar 29, 2017
  4. nullp0tr commented on Feb 19, 2018

    @nullp0tr

    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?

  5. gvanrossum commented on Feb 19, 2018

    @gvanrossum
    Member

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

  6. nullp0tr commented on Feb 20, 2018

    @nullp0tr

    Thanks for the clarification.

  7. OJFord commented on Nov 13, 2018

    @OJFord

    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.

  8. gvanrossum commented on Nov 13, 2018

    @gvanrossum
    Member
  9. 59 remaining items

  10. hauntsaninja commented on Sep 19, 2022

    @hauntsaninja
    Collaborator

    Soon, follow #13385

  11. analog-cbarber commented on Oct 20, 2022

    @analog-cbarber
    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?

  12. bew commented on Oct 20, 2022

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

    ?

  13. analog-cbarber commented on Oct 20, 2022

    @analog-cbarber
    Contributor

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

  14. leycec commented on Oct 21, 2022

    @leycec

    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.

  15. OJFord commented on Oct 21, 2022

    @OJFord

    @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.

  16. added a commit that references this issue on Feb 26, 2023
  17. samskiter commented on Dec 9, 2023

    @samskiter

    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)

  18. added a commit that references this issue on Jan 19, 2024
  19. added a commit that references this issue on Feb 20, 2024
  20. hhartzer commented on Mar 12, 2024

    @hhartzer

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

  21. locked as resolved and limited conversation to collaborators on Mar 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions