Skip to main content
1 vote
1 answer
79 views

attrs subclass from non-attrs class not respecting initializer arguments

I get the following error: $ python attrs_subclass_test.py Traceback (most recent call last): File "attrs_subclass_test.py", line 23, in <module> attrs_sub = AttrsSub(name='...
BrendanSimon's user avatar
3 votes
1 answer
113 views

Is there a decorator for attrs factory sugar?

Similar to Decorator for attrs converter, please see this case: from attrs import define, field, Factory @define class MyClass: name = field(default = Factory(_name_factory, takes_self=True), ...
Daemon Painter's user avatar
1 vote
2 answers
113 views

Dataclass/attrs based orm models and their relationships

I 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 ...
5th's user avatar
  • 2,515
0 votes
0 answers
34 views

Proper approach for a class to call an abstract parent method during instantiation with attrs

I 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 ...
Aristide's user avatar
1 vote
1 answer
67 views

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 ...
RedRuin's user avatar
  • 196
0 votes
1 answer
122 views

attrs and class variables

I 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 ...
mcocdawc's user avatar
  • 1,897
0 votes
1 answer
62 views

Use attrs or_ validator with mypy

I'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 ...
I like Bananas's user avatar
0 votes
1 answer
91 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 ...
mballu's user avatar
  • 3
0 votes
1 answer
47 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....
maxwell_rob33's user avatar
0 votes
1 answer
93 views

Enum of dataclass works but frozen attrs doesn't

The 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 ...
obk's user avatar
  • 846
0 votes
1 answer
187 views

Unsupported converter, only named functions, types and lambdas are currently supported

Using 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 ...
Sebastian Souza Tarnowski's user avatar
0 votes
2 answers
842 views

using attrs pre-commit mypy error: Unexpected keyword argument

mypy 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( ...
Sebastian Souza Tarnowski's user avatar
0 votes
1 answer
134 views

How to implement class composition

Hi 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 ...
Al_'s user avatar
  • 1
0 votes
1 answer
64 views

Pylint warnings with attrs

I 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: ...
Al_'s user avatar
  • 1
0 votes
0 answers
54 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): ...
slaughter98's user avatar
  • 1,911

15 30 50 per page
1
2 3 4 5
12