Skip to content

Commit

Permalink
🐛 Remove trailing comma from ReplaceImportsCodemod
Browse files Browse the repository at this point in the history
  • Loading branch information
Kludex committed Jun 30, 2023
1 parent 0cd8d34 commit ce75aee
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 48 deletions.
1 change: 1 addition & 0 deletions bump_pydantic/codemods/replace_imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ def leave_replace_import(self, _: cst.ImportFrom, updated_node: cst.ImportFrom)
AddImportsVisitor.add_needed_import(self.context, *import_info.to_import_str)
if len(updated_node.names) > 1: # type: ignore
names = [alias for alias in aliases if alias.name.value != import_info.to_import_str[-1]]
names[-1] = names[-1].with_changes(comma=cst.MaybeSentinel.DEFAULT)
updated_node = updated_node.with_changes(names=names)
else:
return cst.RemoveFromParent() # type: ignore[return-value]
Expand Down
78 changes: 30 additions & 48 deletions tests/integration/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,15 +129,6 @@ def before() -> Folder:
" ...",
],
),
# File(
# "rename_method.py",
# content=[
# "from project.add_none import A",
# "",
# 'a = A(a=1, b=2, c=3, d=4, e={"ha": "ha"})',
# "a.dict()",
# ],
# ),
File(
"replace_generic.py",
content=[
Expand Down Expand Up @@ -206,21 +197,21 @@ def before() -> Folder:
" a: A = Field(A.a, const=True)",
],
),
# File(
# "config_dict_and_settings.py",
# content=[
# "from pydantic import BaseModel, BaseSettings",
# "",
# "",
# "class Settings(BaseSettings):",
# " sentry_dsn: str",
# "",
# "",
# "class A(BaseModel):",
# " class Config:",
# " orm_mode = True",
# ]
# )
File(
"config_dict_and_settings.py",
content=[
"from pydantic import BaseModel, BaseSettings",
"",
"",
"class Settings(BaseSettings):",
" sentry_dsn: str",
"",
"",
"class A(BaseModel):",
" class Config:",
" orm_mode = True",
],
),
)


Expand Down Expand Up @@ -277,15 +268,6 @@ def expected() -> Folder:
" ...",
],
),
# File(
# "rename_method.py",
# content=[
# "from project.add_none import A",
# "",
# 'a = A(a=1, b=2, c=3, d=4, e={"ha": "ha"})',
# "a.dict()",
# ],
# ),
File(
"replace_generic.py",
content=[
Expand Down Expand Up @@ -356,21 +338,21 @@ def expected() -> Folder:
" a: Literal[A.a] = A.a",
],
),
# File(
# "config_dict_and_settings.py",
# content=[
# "from pydantic import ConfigDict, BaseModel",
# "from pydantic_settings import BaseSettings",
# "",
# "",
# "class Settings(BaseSettings):",
# " sentry_dsn: str",
# "",
# "",
# "class A(BaseModel):",
# " model_config = ConfigDict(orm_mode=True)",
# ]
# )
File(
"config_dict_and_settings.py",
content=[
"from pydantic import ConfigDict, BaseModel",
"from pydantic_settings import BaseSettings",
"",
"",
"class Settings(BaseSettings):",
" sentry_dsn: str",
"",
"",
"class A(BaseModel):",
" model_config = ConfigDict(from_attributes=True)",
],
),
)


Expand Down

0 comments on commit ce75aee

Please sign in to comment.