It sure does work:

from dataclasses import dataclass

@dataclass
class Test:
    _name: str="schbell"

    @property
    def name(self) -> str:
        return self._name

    @name.setter
    def name(self, v: str) -> None:
        self._name = v

t = Test()
print(t.name) # schbell
t.name = "flirp"
print(t.name) # flirp
print(t) # Test(_name='flirp')

In fact, why should it not? In the end, what you get is just a good old class, derived from type:

print(type(t)) # <class '__main__.Test'>
print(type(Test)) # <class 'type'>

Maybe that's why properties are nowhere mentioned specifically. However, the PEP-557's Abstract mentions the general usability of well-known Python class features:

Because Data Classes use normal class definition syntax, you are free to use inheritance, metaclasses, docstrings, user-defined methods, class factories, and other Python class features.

Answer from shmee on Stack Overflow
🌐
Python
docs.python.org › 3 › library › dataclasses.html
dataclasses — Data Classes
1 month ago - This module provides a decorator and functions for automatically adding generated special methods such as __init__() and __repr__() to user-defined classes. It was originally described in PEP 557.
Discussions

How does Python interpret whether a dataclass attribute is an instance attribute or a class attribute?
Dataclasses have a metaclass that augments the structure with the desired properties. So through them you get to modify default behaviors of the class and instances of the class. More on reddit.com
🌐 r/learnpython
4
2
September 21, 2022
Allow overriding (abstract) properties with fields - Ideas - Discussions on Python.org
I often find myself wanting to do someting like this: from abc import abstractmethod from dataclasses import dataclass class HasLength: @property @abstractmethod def len(self) -> int: ... def __len__(s… More on discuss.python.org
🌐 discuss.python.org
3
November 20, 2022
When to use @cached_property over @property @cache?
Hi, I’m adding an invariant computed property to an “immutable” dataclass. After reading the documentation of the @functools.cached_property it’s not clear to me which approach is preferred for my case: @cached_property or @property @cache. More on discuss.python.org
🌐 discuss.python.org
0
0
October 17, 2022
Reconciling Dataclasses And Properties In Python - Florimond Manca
Reconciling Dataclasses And Properties In Python - Florimond Manca I love Python dataclasses, but combining them with properties is not obvious. This is a problem solving report — and a practical i... More on github.com
🌐 github.com
6
February 26, 2022
🌐
Florimond Manca
florimond.dev › en › posts › 2018 › 10 › reconciling-dataclasses-and-properties-in-python
Reconciling Dataclasses And Properties In Python - Florimond Manca
October 10, 2018 - In short, dataclasses are a simple, elegant, Pythonic way of creating classes that hold data. 🐍 ... I sometimes resort to the @property decorator to implement specific logic when getting/setting an attribute.
🌐
DZone
dzone.com › coding › languages › understanding python's dataclass decorator
Understanding Python's dataclass Decorator
January 29, 2024 - @dataclass is a decorator which is part of the Python dataclasses module.
🌐
Ritviknag
dcw.ritviknag.com › en › latest › using_field_properties.html
Using Field Properties — Dataclass Wizard 0.39.1 documentation
Here is how I’d define the use of a field property in Python dataclasses: A property that is also defined as dataclass field, such that an initial value can be set or passed in via the constructor method. This is mostly just syntactic sugar, to hint to the dataclass decorator that you want to add a parameter to the constructor and associate it with the property.
🌐
Python
typing.python.org › en › latest › spec › dataclasses.html
Dataclasses — typing documentation
If dataclass_transform is applied to a function, using the decorated function as a decorator is assumed to apply dataclass-like semantics. If the function has overloads, the dataclass_transform decorator can be applied to the implementation of the function or any one, but not more than one, ...
Find elsewhere
🌐
Python
peps.python.org › pep-0557
PEP 557 – Data Classes | peps.python.org
Such a class is called a Data Class, but there’s really nothing special about the class: the decorator adds generated methods to the class and returns the same class it was given. ... @dataclass class InventoryItem: '''Class for keeping track of an item in inventory.''' name: str unit_price: float quantity_on_hand: int = 0 def total_cost(self) -> float: return self.unit_price * self.quantity_on_hand
🌐
Real Python
realpython.com › python-property
Python's property(): Add Managed Attributes to Your Classes – Real Python
December 15, 2024 - A property in Python is a tool for creating managed attributes in classes. The @property decorator allows you to define getter, setter, and deleter methods for attributes.
🌐
Quick Adviser
quick-adviser.com › home › blog
What is Property decorator? – QuickAdviser
May 15, 2019 - @property decorator is a built-in decorator in Python which is helpful in defining the properties effortlessly without manually calling the inbuilt function property(). Which is used to return the property attributes of a class from the stated getter, setter and deleter as parameters.
🌐
Plain English
plainenglish.io › home › blog › python › dataclasses :  init-only properties
Dataclasses : init-only Properties
December 14, 2023 - Dataclasses generates the __init__ method based on the defined properties with a direct assignment of the values. This will work for our prop1, prop2, and prop3 properties, but for patter_str, we do not want to store the raw pattern, but the ...
🌐
Reddit
reddit.com › r/learnpython › how does python interpret whether a dataclass attribute is an instance attribute or a class attribute?
r/learnpython on Reddit: How does Python interpret whether a dataclass attribute is an instance attribute or a class attribute?
September 21, 2022 -

I read on SO about the below example:

# Case 1
class Foo:
    x: int
# At this point, x has no value, so doesn't actually exist as a variable.

# Case 2
class Foo:
    y: int = 3
# You are creating both a class variable and an annotation

Is dataclass an exception? As a class attribute in a dataclass must be annotated with ClassVar.

In a dataclass, a type-annotated attribute with a default value provided, does  a class attribute
🌐
Python
docs.python.org › fr › 3.7 › library › dataclasses.html
dataclasses — Classes de Données — Documentation Python 3.7.17
If the default value of a field is specified by a call to field(), then the class attribute for this field will be replaced by the specified default value. If no default is provided, then the class attribute will be deleted. The intent is that after the dataclass() decorator runs, the class attributes will all contain the default values for the fields, just as if the default value itself were specified.
🌐
Python.org
discuss.python.org › ideas
Allow overriding (abstract) properties with fields - Ideas - Discussions on Python.org
November 20, 2022 - I often find myself wanting to do someting like this: from abc import abstractmethod from dataclasses import dataclass class HasLength: @property @abstractmethod def len(self) -> int: ... def __len__(s…
🌐
Teqnation
teqnation.com › how-to-use-python-dataclasses
How to use Python dataclasses – TEQnation – Platform
It also preserves the type information for each property, so if you use a code linter like mypy, it will ensure that you’re supplying the right kinds of variables to the class constructor. Another thing @dataclass does behind the scenes is automatically create code for a number of common dunder methods in the class. In the conventional class above, we had to create our own __repr__. In the dataclass, this is unnecessary; @dataclass generates the __repr__ for you.
🌐
Python.org
discuss.python.org › python help
When to use @cached_property over @property @cache? - Python Help - Discussions on Python.org
October 17, 2022 - Hi, I’m adding an invariant computed property to an “immutable” dataclass. After reading the documentation of the @functools.cached_property it’s not clear to me which approach is preferred for my case: @cached_propert…
🌐
GitHub
github.com › florimondmanca › www › issues › 387
Reconciling Dataclasses And Properties In Python - Florimond Manca · Issue #387 · florimondmanca/www
February 26, 2022 - Reconciling Dataclasses And Properties In Python - Florimond Manca I love Python dataclasses, but combining them with properties is not obvious. This is a problem solving report — and a practical i...
Author   utterances-bot
🌐
Localcoder
localcoder.org › dataclasses-and-property-decorator
Loading...
We cannot provide a description for this page right now