-
Notifications
You must be signed in to change notification settings - Fork 16
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
check-class-attributes=True does not work for attrs-class #140
Comments
* Pin pydoclint to version 0.5.1 (now also in pre-commit) * Deactivate incompatible `check-class-attributes` option For details, see: # jsh9/pydoclint#140
* Pin pydoclint to version 0.5.1 (now also in pre-commit) * Deactivate incompatible `check-class-attributes` option For details, see: jsh9/pydoclint#140
Workaround to avoid attrs incompatibility. For details, see: jsh9/pydoclint#140
Hi @Waschenbacher , I'm a bit confused, because I think the behavior of pydoclint is the correct behavior. @define
class EmployeeAttrs:
"""Class related to employee."""
name: str = field() In this class def, @define
class EmployeeAttrs:
"""
Class related to employee.
Attributes:
name (str): Employee's name
"""
name: str = field() |
Hi @jsh9, for class-building frameworks like Since |
Hi @AdrianSosic and @Waschenbacher , sorry about the delayed response here. In your opinion, what should the expected behavior of pydoclint be? Thanks! |
I think the answer is rather simple here: the behavior should be identical to the one in the case of plain python classes, only the way class attributes are identified needs to be adjusted. That is, in all three cases, (attrs, dataclass, pydantic), an attribute only becomes a class variable when it is annotated with |
I see. This makes sense. Here is the logic that I have in mind: I would add a new config option called This option is by default What do you think of this logic? Additionally, I have a question. In this example: from typing import ClassVar
class MyClass:
attr_1: ClassVar[int] = 0
attr_2: int = 2
def __init__(self) -> None:
self.attr_3: ClassVar[str] = 'hello' Is it correct to write |
Hi @jsh9, writing from my phone hence I've very limited capabilities here. But I think perhaps I haven't made myself perfectly clear because it appears to me you are mixing up a few things. The Therefore: what we are talking about here is not a question on backwards compatibility -- you can use regular python classes and the auto-created ones at the same time and there will be no ambiguities. So the question rather becomes: how can you reliably check if a dataclass-like mechanisms is in place? Here on my phone it's hard to check but afaik there is a PEP that now officially supports dataclass related interfaces. Potentially one could follow that approach. Can try to find it once I sent this message or next week when I'm back at work. |
Got it: Perhaps this offers a solution |
Hi @AdrianSosic , maybe you could show me examples for This could help me better understand this. Thanks! |
Sure, can do next week when I'm back. In case I forget, feel free to ping me 👍 |
Hi @AdrianSosic , did you happen to have some time to look at this? Thanks! |
Hi @jsh9, thanks for the reminder, I knew I would forget 😅 Here the code snippets for the three frameworks, all implementing the identical logic. from dataclasses import dataclass
from typing import ClassVar
from attrs import define, field
from pydantic import BaseModel, Field
@define
class AttrsClass:
c: ClassVar[bool] = True # class attribute
x: int # instance attribute
y: float = 1.0 # instance attribute
z: str = field(default="abc") # instance attribute
@dataclass
class DataClass:
c: ClassVar[bool] = True # class attribute
x: int # instance attribute
y: float = 1.0 # instance attribute
z: str = field(default="abc") # instance attribute
class PydanticClass(BaseModel):
c: ClassVar[bool] = True # class attribute
x: int # instance attribute
y: float = 1.0 # instance attribute
z: str = Field(default="abc") # instance attribute Note that only @define
class WithDocstring:
x: int
"""This is an int.""" I guess the same is true for Does that help? |
Hi @Waschenbacher and @AdrianSosic , I made a code change to add a new config option |
@jsh9 Thanks for the update! |
It seems that
check-class-attributes=True
works for pure-python class but not for attrs-classes. Would it be possible to support the attrs-class withcheck-class-attributes=True
as well? Thanks.To reproduce:
pydoclint error message:
The text was updated successfully, but these errors were encountered: