0 votes
2 answers
82 views
Dataclass/attrs based orm models and their relationshipsI am building a small python application to learn Domain-Driven-Design (DDD) approaches. Therefore I am using a dataclass/attrs class as my domain model and also use this class to imperatively model ...
asked May 5 at 20:280 votes
0 answers
32 views
Proper approach for a class to call an abstract parent method during instantiation with attrsI have the following abstract class defining a couple abstract methods that should be defined in every children. To avoid repetition in every children, those methods are ran from the method ...
asked Apr 8 at 15:24 How to issue warnings from a `attrs` validator with correct `stacklevel`?I want to use validators to issue warnings for notable but non-catastrophic issues on classes. However, by default warnings will point to the place where the warning was defined, and I want to have ...
asked Mar 20 at 14:390 votes
1 answer
102 views
attrs and class variablesI really like the way how one can define classes via the attrs library. In particular how the usual syntax of python class variables is hijacked to define instance variables. But is there a way to get ...
asked Dec 12, 2024 at 19:300 votes
1 answer
54 views
Use attrs or_ validator with mypyI'm trying to use attrs to define a class that has an attribute that can be either a str or an int. The or_ validator see;s to be exactly what I need but mypy throws an error when using the exact ...
asked Dec 11, 2024 at 14:380 votes
1 answer
78 views
cattrs : can I use a json converter in a class method to instantiate an object from a json file?I have been an extensive user of attrs for two years, but I have discovered cattrs only recently so my question may sound naive. In my codes, I often use a class method to instantiate an attrs object ...
asked Dec 6, 2024 at 9:100 votes
1 answer
40 views
Is there a way to signal an attrs class field so it won't be part of deepcopy / pickle?I find myself often writing attrs classes that looks something like this: import attrs from some_app import Client @attrs.mutable class Foo: _credentials: str = attrs.field(validator=attrs....
asked Nov 25, 2024 at 15:520 votes
1 answer
83 views
Enum of dataclass works but frozen attrs doesn'tThe built-in enum provides a way to create enums of primitive types (IntEnum, StrEnum). I'd like to create an enum of structured objects. One way to do that is with dataclass, and it works: from ...
asked Oct 20, 2024 at 1:210 votes
1 answer
162 views
Unsupported converter, only named functions, types and lambdas are currently supportedUsing the complicated example as here https://www.attrs.org/en/stable/api.html#attrs.converters.default_if_none, I get the mypy error: Unsupported converter, only named functions, types and lambdas ...
asked Oct 11, 2024 at 22:050 votes
2 answers
779 views
using attrs pre-commit mypy error: Unexpected keyword argumentmypy runs perfectly on terminal, but when running on pre-commit stage, I am getting the error Unexpected keyword argument for every property in my class from attrs import define, field @define( ...
asked Sep 4, 2024 at 17:370 votes
1 answer
133 views
How to implement class compositionHi I have a model that contain several items, now all of the items have a set of shared properties: id, name, parent. In addition some of this items are meant only to contain other items. Some are ...
asked May 3, 2024 at 13:220 votes
1 answer
58 views
Pylint warnings with attrsI keep getting warnings from pylint while trying to iterate over an attribute in a class that uses the attrs package. from typing import List from attrs import define, Factory @define class MyClass: ...
asked May 2, 2024 at 16:040 votes
0 answers
49 views
Is it possible to utilize a lambda function in an python-attrs converter? [duplicate]I am attempting to automatically create converter functions that require metadata to operate. I am seeing odd behavior when a lambda function is used for the converter. import attrs def add(x, y=10): ...
asked Apr 17, 2024 at 7:431 vote
1 answer
227 views
In python Attrs package, how to add a field in the field_transformer function?The documentation for the python Attrs, the Automatic Field Transformation and Modification section states ...You can add converters, change types, and even remove attributes completely or create new ...
asked Apr 17, 2024 at 3:310 votes
1 answer
1k views
Pyright cause reportAttributeAccessIssue on attrs validatorEnvironment Python v3.9.13 Pyright 1.1.357 attrs 23.1.0 The code at official document of attrs library make the pyright type checker casue reportAttributeAccessIssue https://www.attrs.org/en/stable/...
asked Apr 16, 2024 at 1:30RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4