ruff/crates/ruff_linter/resources/test/fixtures/pyupgrade/UP036_5.py
InSync 7fbd89cb39
[pyupgrade] Handle micro version numbers correctly (UP036) (#16091)
## Summary

Resolves #16082.

`UP036` will now also take into consideration whether or not a micro
version number is set:

* If a third element doesn't exist, the existing logic is preserved.
* If it exists but is not an integer literal, the check will not be
reported.
* If it is an integer literal but doesn't fit into a `u8`, the check
will be reported as invalid.
* Otherwise, the compared version is determined to always be less than
the target version when:
	* The target's minor version is smaller than that of the comparator, or
* The operator is `<`, the micro version is 0, and the two minor
versions compare equal.

As this is considered a bugfix, it is not preview-gated.

## Test Plan

`cargo nextest run` and `cargo insta test`.

---------

Co-authored-by: Micha Reiser <micha@reiser.io>
2025-02-11 07:40:56 +00:00

73 lines
1 KiB
Python

import sys
if sys.version_info < (3, 8):
def a():
if b:
print(1)
elif c:
print(2)
return None
else:
pass
import sys
if sys.version_info < (3, 8):
pass
else:
def a():
if b:
print(1)
elif c:
print(2)
else:
print(3)
return None
# https://github.com/astral-sh/ruff/issues/16082
## Errors
if sys.version_info < (3, 12, 0):
print()
if sys.version_info <= (3, 12, 0):
print()
if sys.version_info < (3, 12, 11):
print()
if sys.version_info < (3, 13, 0):
print()
if sys.version_info <= (3, 13, 100000):
print()
## No errors
if sys.version_info <= (3, 13, foo):
print()
if sys.version_info <= (3, 13, 'final'):
print()
if sys.version_info <= (3, 13, 0):
print()
if sys.version_info < (3, 13, 37):
print()
if sys.version_info <= (3, 13, 37):
print()
if sys.version_info <= (3, 14, 0):
print()
if sys.version_info <= (3, 14, 15):
print()