Skip to content

Commit 61af600

Browse files
committed
fix: Linting errors.
1 parent b684d11 commit 61af600

File tree

3 files changed

+34
-34
lines changed

3 files changed

+34
-34
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ example: Example = load_settings(Example, nested_delimiter='_')
6464
### Clarity
6565

6666
- `pydantic-settings` makes it really, really difficult to intuit what the
67-
concrete environment varibale that's going to be loaded for a given field is
67+
concrete environment variable that's going to be loaded for a given field is
6868
**actually** going to be. Based on my own experience, and from perusing their
6969
issue tracker, it seems like this is not an uncommon experience.
7070

@@ -127,7 +127,7 @@ example: Example = load_settings(Example, nested_delimiter='_')
127127

128128
Practically, `pydantic` has the most robust system for parsing/validating a
129129
json-like structure into the models, so it's probably to be the most flexible
130-
anyways. But for many simple cases, particuarly those without nesting, or that
130+
anyways. But for many simple cases, particularly those without nesting, or that
131131
only deal in simple types (like int, float, str, etc); then dataclasses/attrs
132132
can certainly provide a similar experience.
133133

src/dataclass_settings/class_inspect.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@ def map_value(self, value: str | dict[str, Any]):
6565
@dataclasses.dataclass
6666
class DataclassField(Field):
6767
@classmethod
68-
def collect(cls, typ: type, type_hints: dict[str, Type]) -> list[Self]:
68+
def collect(cls, value: type, type_hints: dict[str, Type]) -> list[Self]:
6969
fields = []
70-
for f in typ.__dataclass_fields__.values(): # type: ignore
70+
for f in value.__dataclass_fields__.values(): # type: ignore
7171
annotation = get_type(type_hints[f.name])
7272

7373
annotation, args = get_annotation_args(annotation)
@@ -85,10 +85,10 @@ def collect(cls, typ: type, type_hints: dict[str, Type]) -> list[Self]:
8585
@dataclasses.dataclass
8686
class AttrsField(Field):
8787
@classmethod
88-
def collect(cls, typ: type, type_hints: dict[str, Type]) -> list[Self]:
88+
def collect(cls, value: type, type_hints: dict[str, Type]) -> list[Self]:
8989
fields = []
9090

91-
for f in typ.__attrs_attrs__: # type: ignore
91+
for f in value.__attrs_attrs__: # type: ignore
9292
annotation = get_type(type_hints[f.name])
9393
annotation, args = get_annotation_args(annotation)
9494

@@ -105,11 +105,11 @@ def collect(cls, typ: type, type_hints: dict[str, Type]) -> list[Self]:
105105
@dataclasses.dataclass
106106
class MsgspecField(Field):
107107
@classmethod
108-
def collect(cls, typ: type, type_hints: dict[str, Type]) -> list[Self]:
108+
def collect(cls, value: type, type_hints: dict[str, Type]) -> list[Self]:
109109
import msgspec
110110

111111
fields = []
112-
for f in msgspec.structs.fields(typ):
112+
for f in msgspec.structs.fields(value):
113113
annotation = get_type(type_hints[f.name])
114114
annotation, args = get_annotation_args(annotation)
115115

@@ -137,9 +137,9 @@ def convert(**value):
137137
@dataclasses.dataclass
138138
class PydanticV1Field(Field):
139139
@classmethod
140-
def collect(cls, typ, type_hints: dict[str, Type]) -> list[Self]:
140+
def collect(cls, value, type_hints: dict[str, Type]) -> list[Self]:
141141
fields = []
142-
for name, f in typ.__fields__.items():
142+
for name, f in value.__fields__.items():
143143
annotation = get_type(type_hints[name])
144144
annotation, args = get_annotation_args(annotation)
145145

@@ -158,9 +158,9 @@ def collect(cls, typ, type_hints: dict[str, Type]) -> list[Self]:
158158
@dataclasses.dataclass
159159
class PydanticV2Field(Field):
160160
@classmethod
161-
def collect(cls, typ: type, type_hints: dict[str, Type]) -> list[Self]:
161+
def collect(cls, value: type, type_hints: dict[str, Type]) -> list[Self]:
162162
fields = []
163-
for name, f in typ.model_fields.items(): # type: ignore
163+
for name, f in value.model_fields.items(): # type: ignore
164164
annotation = get_type(type_hints[name])
165165
mapper = annotation if detect(annotation) else None
166166

@@ -177,10 +177,10 @@ def collect(cls, typ: type, type_hints: dict[str, Type]) -> list[Self]:
177177
@dataclasses.dataclass
178178
class PydanticV2DataclassField(Field):
179179
@classmethod
180-
def collect(cls, typ: type, type_hints: dict[str, Type]) -> list[Self]:
180+
def collect(cls, value: type, type_hints: dict[str, Type]) -> list[Self]:
181181
fields = []
182182

183-
for name, f in typ.__pydantic_fields__.items(): # type: ignore
183+
for name, f in value.__pydantic_fields__.items(): # type: ignore
184184
annotation = get_type(type_hints[name])
185185
mapper = annotation if detect(annotation) else None
186186

@@ -248,10 +248,10 @@ def from_cls(cls, obj: type) -> ClassTypes | None:
248248
return None
249249

250250

251-
def get_type(typ):
252-
if typing_inspect.is_optional_type(typ):
253-
return get_args(typ)[0]
254-
return typ
251+
def get_type(value):
252+
if typing_inspect.is_optional_type(value):
253+
return get_args(value)[0]
254+
return value
255255

256256

257257
def get_annotation_args(annotation) -> Tuple[Type, Tuple[Any, ...]]:

tests/loaders/test_toml.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class AttrRequired:
7171
str,
7272
Toml(
7373
Path(__file__).parent.parent.parent / "pyproject.toml",
74-
"project.license",
74+
"project.license.file",
7575
),
7676
]
7777
ignoreme: str = "asdf"
@@ -87,7 +87,7 @@ class DataclassRequired:
8787
str,
8888
Toml(
8989
Path(__file__).parent.parent.parent / "pyproject.toml",
90-
"project.license",
90+
"project.license.file",
9191
),
9292
]
9393
ignoreme: str = "asdf"
@@ -102,7 +102,7 @@ class MsgspecRequired(Struct):
102102
str,
103103
Toml(
104104
Path(__file__).parent.parent.parent / "pyproject.toml",
105-
"project.license",
105+
"project.license.file",
106106
),
107107
]
108108
ignoreme: str = "asdf"
@@ -120,7 +120,7 @@ class PydanticRequired(BaseModel):
120120
str,
121121
Toml(
122122
Path(__file__).parent.parent.parent / "pyproject.toml",
123-
"project.license",
123+
"project.license.file",
124124
),
125125
]
126126
ignoreme: str = "asdf"
@@ -139,7 +139,7 @@ class PDataclassRequired:
139139
str,
140140
Toml(
141141
Path(__file__).parent.parent.parent / "pyproject.toml",
142-
"project.license",
142+
"project.license.file",
143143
),
144144
]
145145
ignoreme: str = "asdf"
@@ -159,34 +159,34 @@ class PDataclassRequired:
159159
def test_has_required_required(config_class):
160160
config = load_settings(config_class)
161161
assert config == config_class(
162-
foo="dataclass-settings", ignoreme="asdf", license="Apache-2.0"
162+
foo="dataclass-settings", ignoreme="asdf", license="LICENSE"
163163
)
164164

165165

166166
@attr_dataclass
167-
class AttrMissingOptionelInferred:
167+
class AttrMissingOptionalInferred:
168168
tool: Annotated[int, Toml(Path(__file__).parent.parent.parent / "pyproject.toml")]
169169
ignoreme: str = "asdf"
170170

171171

172172
@dataclass
173-
class DataclassMissingOptionelInferred:
173+
class DataclassMissingOptionalInferred:
174174
tool: Annotated[int, Toml(Path(__file__).parent.parent.parent / "pyproject.toml")]
175175
ignoreme: str = "asdf"
176176

177177

178-
class MsgspecMissingOptionelInferred(Struct):
178+
class MsgspecMissingOptionalInferred(Struct):
179179
tool: Annotated[int, Toml(Path(__file__).parent.parent.parent / "pyproject.toml")]
180180
ignoreme: str = "asdf"
181181

182182

183-
class PydanticMissingOptionelInferred(BaseModel):
183+
class PydanticMissingOptionalInferred(BaseModel):
184184
tool: Annotated[int, Toml(Path(__file__).parent.parent.parent / "pyproject.toml")]
185185
ignoreme: str = "asdf"
186186

187187

188188
@pydantic_dataclass
189-
class PDataclassMissingOptionelInferred:
189+
class PDataclassMissingOptionalInferred:
190190
tool: Annotated[int, Toml(Path(__file__).parent.parent.parent / "pyproject.toml")]
191191
ignoreme: str = "asdf"
192192

@@ -195,11 +195,11 @@ class PDataclassMissingOptionelInferred:
195195
@pytest.mark.parametrize(
196196
"config_class",
197197
[
198-
AttrMissingOptionelInferred,
199-
DataclassMissingOptionelInferred,
200-
MsgspecMissingOptionelInferred,
201-
PydanticMissingOptionelInferred,
202-
PDataclassMissingOptionelInferred,
198+
AttrMissingOptionalInferred,
199+
DataclassMissingOptionalInferred,
200+
MsgspecMissingOptionalInferred,
201+
PydanticMissingOptionalInferred,
202+
PDataclassMissingOptionalInferred,
203203
],
204204
)
205205
def test_missing_optional_inferred_name(config_class):

0 commit comments

Comments
 (0)