Skip to content
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

Added Django 4.2+ fixer for “Set” assert methods #253

Merged
merged 9 commits into from
Feb 11, 2023

Conversation

icemac
Copy link
Contributor

@icemac icemac commented Sep 25, 2022

Fixes #252.

Copy link
Owner

@adamchainz adamchainz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thansk for the PR, yes I'll delay merging it until after Django 4.2 is in RC

Comment on lines 29 to 42
@fixer.register(ast.Attribute)
def visit_Attribute(
state: State,
node: ast.Attribute,
parents: list[ast.AST],
) -> Iterable[tuple[Offset, TokenFunc]]:
if (
(name := node.attr) in NAMES
and isinstance(node.value, ast.Name)
and node.value.id == "self"
):
yield ast_start_offset(node), partial(
find_and_replace_name, name=name, new=NAMES[name]
)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we instead check for ast.Call nodes that have an ast.Attribute as their func? This would be slightly more precise, which is good for avoiding false positives.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@adamchainz I changed my code according to your suggestion, see 0bc330e. Do you think it is okay now?

Copy link
Owner

@adamchainz adamchainz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah looks good! Now we just need to wait for the Django 4.2 RC1.

We'll also need to add 4.2 as an allowed target version, if you want to add that in this PR:

parser.add_argument(
"--target-version",
default="2.2",
choices=[
"1.7",
"1.8",
"1.9",
"1.10",
"1.11",
"2.0",
"2.1",
"2.2",
"3.0",
"3.1",
"3.2",
"4.0",
"4.1",
],
)

@icemac
Copy link
Contributor Author

icemac commented Oct 13, 2022

We'll also need to add 4.2 as an allowed target version, if you want to add that in this PR:

Done in 3ba65c4.

@adamchainz
Copy link
Owner

Great, now we play the waiting game.

src/django_upgrade/fixers/testcase_methods.py Outdated Show resolved Hide resolved
src/django_upgrade/fixers/testcase_methods.py Outdated Show resolved Hide resolved
README.rst Outdated Show resolved Hide resolved
@adamchainz
Copy link
Owner

I said "RC" but Django 4.2 alpha 1 is out, and that's a good time to merge and release I think. People can start their test branches and run django-upgrade to clear this deprecation warning.

@adamchainz adamchainz changed the title Added fixer to rewrite assertFormsetError and assertQuerysetEqual. Added Django 4.2+ fixer for “Set” assert methods Feb 11, 2023
@adamchainz adamchainz merged commit 89a193e into adamchainz:main Feb 11, 2023
@icemac icemac deleted the ticket_33990 branch February 21, 2023 07:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Django 4.2: Rename assertFormsetError and assertQuerysetEqual
2 participants