-
-
Notifications
You must be signed in to change notification settings - Fork 184
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
rewrite to datetime.UTC #764
Conversation
isinstance(parent, ast.Attribute) and | ||
parent.attr == 'utc' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
parent should be avoided when possible -- this should start from the datetime
Attribute
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've just pushed a new version without parent
. Did I get it right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
datetime
is not an attribute, but a Name
.
@pytest.mark.parametrize( | ||
('s', 'expected'), | ||
( | ||
pytest.param( | ||
'import datetime\n' | ||
'print(datetime.timezone.utc)', | ||
|
||
'import datetime\n' | ||
'print(datetime.UTC)', | ||
|
||
id='rewriting to alias', | ||
), | ||
pytest.param( | ||
'import datetime\n' | ||
'print(datetime.timezone(-1))', | ||
|
||
'import datetime\n' | ||
'print(datetime.timezone(-1))', | ||
|
||
id='not rewriting timezone object to alias', | ||
), | ||
), | ||
) | ||
def test_fix_datetime_utc_alias(s, expected): | ||
assert _fix_plugins(s, settings=Settings(min_version=(3,))) == s | ||
assert _fix_plugins(s, settings=Settings(min_version=(3, 11))) == expected |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there should be clearly separate noop and non-noop tests -- please follow one of the other tests as an example
Rewrite: ```python import datetime datetime.timezone.utc ``` to alias: ```python import datetime datetime.UTC ``` in Python >= 3.11. Fixes: #755
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rewrite:
to alias:
in Python >= 3.11.
Fixes: #755