Skip to content

Commit

Permalink
Merge branch 'main' into add-too-many-positional
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh committed Dec 4, 2023
2 parents 600032a + bfae1f1 commit cc81842
Show file tree
Hide file tree
Showing 64 changed files with 3,096 additions and 1,278 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,18 @@ def func():
for i in range(1110):
if True:
break

# TODO(charlie): The `pass` here does not get properly redirected to the top of the
# loop, unlike below.
def func():
for i in range(5):
pass
else:
return 1

def func():
for i in range(5):
pass
else:
return 1
x = 1
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,11 @@ class Color(Enum):
print("Grass is green")
case Color.BLUE:
print("I'm feeling the blues :(")


def func(point):
match point:
case (0, 0):
print("Origin")
case foo:
raise ValueError("oops")
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,87 @@ def func(x: int):
return "str"
else:
return None


def func(x: int):
if x:
return 1


def func():
x = 1


def func(x: int):
if x > 0:
return 1


def func(x: int):
match x:
case [1, 2, 3]:
return 1
case 4 as y:
return "foo"


def func(x: int):
for i in range(5):
if i > 0:
return 1


def func(x: int):
for i in range(5):
if i > 0:
return 1
else:
return 4


def func(x: int):
for i in range(5):
if i > 0:
break
else:
return 4


def func(x: int):
try:
pass
except:
return 1


def func(x: int):
try:
pass
except:
return 1
finally:
return 2


def func(x: int):
try:
pass
except:
return 1
else:
return 2


def func(x: int):
try:
return 1
except:
return 2
else:
pass


def func(x: int):
while x > 0:
break
return 1
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,7 @@

# check that this edge case doesn't crash
_: TypeAlias = str | int

# PEP 695
type foo_bar = int | str
type FooBar = int | str
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,7 @@ Snake_case_alias: TypeAlias = int | float # PYI042, since not camel case

# check that this edge case doesn't crash
_: TypeAlias = str | int

# PEP 695
type foo_bar = int | str
type FooBar = int | str
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,7 @@

# check that this edge case doesn't crash
_: TypeAlias = str | int

# PEP 695
type _FooT = str | int
type Foo = str | int
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,7 @@ _PrivateAliasS2: TypeAlias = Annotated[str, "also okay"]

# check that this edge case doesn't crash
_: TypeAlias = str | int

# PEP 695
type _FooT = str | int
type Foo = str | int
11 changes: 11 additions & 0 deletions crates/ruff_linter/resources/test/fixtures/flake8_pyi/PYI050.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,14 @@ def foo_no_return_typing_extensions(
def foo_no_return_kwarg(arg: int, *, arg2: NoReturn): ... # Error: PYI050
def foo_no_return_pos_only(arg: int, /, arg2: NoReturn): ... # Error: PYI050
def foo_never(arg: Never): ...
def foo_args(*args: NoReturn): ... # Error: PYI050
def foo_kwargs(**kwargs: NoReturn): ... # Error: PYI050
def foo_args_kwargs(*args: NoReturn, **kwargs: NoReturn): ... # Error: PYI050
def foo_int_args(*args: int): ...
def foo_int_kwargs(**kwargs: int): ...
def foo_int_args_kwargs(*args: int, **kwargs: int): ...
def foo_int_args_no_return(*args: int, **kwargs: NoReturn): ... # Error: PYI050
def foo_int_kwargs_no_return(*args: NoReturn, **kwargs: int): ... # Error: PYI050
def foo_args_never(*args: Never): ...
def foo_kwargs_never(**kwargs: Never): ...
def foo_args_kwargs_never(*args: Never, **kwargs: Never): ...
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,6 @@ def model_assign() -> None:

Bad = import_string("django.core.exceptions.ValidationError") # N806
ValidationError = import_string("django.core.exceptions.ValidationError") # OK

Bad = apps.get_model() # N806
Bad = apps.get_model(model_name="Stream") # N806
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,6 @@ def f():
''' # noqa

regex = '\\\_'

#: W605:1:7
u'foo\ bar'
42 changes: 28 additions & 14 deletions crates/ruff_linter/resources/test/fixtures/pycodestyle/W605_1.py
Original file line number Diff line number Diff line change
@@ -1,40 +1,54 @@
# Same as `W605_0.py` but using f-strings instead.

#: W605:1:10
regex = '\.png$'
regex = f'\.png$'

#: W605:2:1
regex = '''
regex = f'''
\.png$
'''

#: W605:2:6
f(
'\_'
f'\_'
)

#: W605:4:6
"""
f"""
multi-line
literal
with \_ somewhere
in the middle
"""

#: W605:1:38
value = f'new line\nand invalid escape \_ here'

def f():
#: W605:1:11
return'\.png$'

#: Okay
regex = r'\.png$'
regex = '\\.png$'
regex = r'''
regex = fr'\.png$'
regex = f'\\.png$'
regex = fr'''
\.png$
'''
regex = r'''
regex = fr'''
\\.png$
'''
s = '\\'
regex = '\w' # noqa
regex = '''
s = f'\\'
regex = f'\w' # noqa
regex = f'''
\w
''' # noqa

regex = f'\\\_'
value = f'\{{1}}'
value = f'\{1}'
value = f'{1:\}'
value = f"{f"\{1}"}"
value = rf"{f"\{1}"}"

# Okay
value = rf'\{{1}}'
value = rf'\{1}'
value = rf'{1:\}'
value = f"{rf"\{1}"}"
54 changes: 0 additions & 54 deletions crates/ruff_linter/resources/test/fixtures/pycodestyle/W605_2.py

This file was deleted.

11 changes: 11 additions & 0 deletions crates/ruff_linter/resources/test/fixtures/pydocstyle/D208.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
"""
Author
"""


class Platform:
""" Remove sampler
Args:
    Returns:
"""


def memory_test():
"""
   参数含义:precision:精确到小数点后几位
"""
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,16 @@ def f(x, y, z, *, u, v, w): # Too many arguments (6/5)

def f(x, y, z, a, b, c, *, u, v, w): # Too many arguments (9/5)
pass


from typing import override, overload


@override
def f(x, y, z, a, b, c, *, u, v, w): # OK
pass


@overload
def f(x, y, z, a, b, c, *, u, v, w): # OK
pass
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,27 @@ def fix_these():
def dont_fix_these():
# once there is an assignment to the dict[index], we stop emitting diagnostics
for fruit_name, fruit_count in FRUITS.items():
FRUITS[fruit_name] = 0 # Ok
assert FRUITS[fruit_name] == 0 # Ok
FRUITS[fruit_name] = 0 # OK
assert FRUITS[fruit_name] == 0 # OK

# once there is an assignment to the key, we stop emitting diagnostics
for fruit_name, fruit_count in FRUITS.items():
fruit_name = 0 # OK
assert FRUITS[fruit_name] == 0 # OK

# once there is an assignment to the value, we stop emitting diagnostics
for fruit_name, fruit_count in FRUITS.items():
if fruit_count < 5:
fruit_count = -fruit_count
assert FRUITS[fruit_name] == 0 # OK


def value_intentionally_unused():
[FRUITS[fruit_name] for fruit_name, _ in FRUITS.items()] # Ok
{FRUITS[fruit_name] for fruit_name, _ in FRUITS.items()} # Ok
{fruit_name: FRUITS[fruit_name] for fruit_name, _ in FRUITS.items()} # Ok
[FRUITS[fruit_name] for fruit_name, _ in FRUITS.items()] # OK
{FRUITS[fruit_name] for fruit_name, _ in FRUITS.items()} # OK
{fruit_name: FRUITS[fruit_name] for fruit_name, _ in FRUITS.items()} # OK

for fruit_name, _ in FRUITS.items():
print(FRUITS[fruit_name]) # Ok
blah = FRUITS[fruit_name] # Ok
assert FRUITS[fruit_name] == "pear" # Ok
print(FRUITS[fruit_name]) # OK
blah = FRUITS[fruit_name] # OK
assert FRUITS[fruit_name] == "pear" # OK
Loading

0 comments on commit cc81842

Please sign in to comment.