mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-29 21:35:58 +00:00
93 lines
2.3 KiB
Python
93 lines
2.3 KiB
Python
#: E251 E251
|
|
def foo(bar = False):
|
|
'''Test function with an error in declaration'''
|
|
pass
|
|
#: E251
|
|
foo(bar= True)
|
|
#: E251
|
|
foo(bar =True)
|
|
#: E251 E251
|
|
foo(bar = True)
|
|
#: E251
|
|
y = bar(root= "sdasd")
|
|
#: E251:2:29
|
|
parser.add_argument('--long-option',
|
|
default=
|
|
"/rather/long/filesystem/path/here/blah/blah/blah")
|
|
#: E251:1:45
|
|
parser.add_argument('--long-option', default
|
|
="/rather/long/filesystem/path/here/blah/blah/blah")
|
|
#: E251:3:8 E251:3:10
|
|
foo(True,
|
|
baz=(1, 2),
|
|
biz = 'foo'
|
|
)
|
|
#: Okay
|
|
foo(bar=(1 == 1))
|
|
foo(bar=(1 != 1))
|
|
foo(bar=(1 >= 1))
|
|
foo(bar=(1 <= 1))
|
|
(options, args) = parser.parse_args()
|
|
d[type(None)] = _deepcopy_atomic
|
|
|
|
# Annotated Function Definitions
|
|
#: Okay
|
|
def munge(input: AnyStr, sep: AnyStr = None, limit=1000,
|
|
extra: Union[str, dict] = None) -> AnyStr:
|
|
pass
|
|
#: Okay
|
|
async def add(a: int = 0, b: int = 0) -> int:
|
|
return a + b
|
|
# Previously E251 four times
|
|
#: E271:1:6
|
|
async def add(a: int = 0, b: int = 0) -> int:
|
|
return a + b
|
|
#: E252:1:15 E252:1:16 E252:1:27 E252:1:36
|
|
def add(a: int=0, b: int =0, c: int= 0) -> int:
|
|
return a + b + c
|
|
#: Okay
|
|
def add(a: int = _default(name='f')):
|
|
return a
|
|
|
|
# F-strings
|
|
f"{a=}"
|
|
f"{a:=1}"
|
|
f"{foo(a=1)}"
|
|
f"normal {f"{a=}"} normal"
|
|
|
|
# Okay as the `=` is used inside a f-string...
|
|
print(f"{foo = }")
|
|
# ...but then it creates false negatives for now
|
|
print(f"{foo(a = 1)}")
|
|
|
|
# There should be at least one E251 diagnostic for each type parameter here:
|
|
def pep_696_bad[A=int, B =str, C= bool, D:object=int, E: object=str, F: object =bool, G: object= bytes]():
|
|
pass
|
|
|
|
class PEP696Bad[A=int, B =str, C= bool, D:object=int, E: object=str, F: object =bool, G: object= bytes]:
|
|
pass
|
|
|
|
# The last of these should cause us to emit E231,
|
|
# but E231 isn't tested by this fixture:
|
|
def pep_696_good[A = int, B: object = str, C:object = memoryview]():
|
|
pass
|
|
|
|
class PEP696Good[A = int, B: object = str, C:object = memoryview]:
|
|
def pep_696_good_method[A = int, B: object = str, C:object = memoryview](self):
|
|
pass
|
|
|
|
|
|
# https://github.com/astral-sh/ruff/issues/15202
|
|
type Coro[T: object = Any] = Coroutine[None, None, T]
|
|
|
|
|
|
# https://github.com/astral-sh/ruff/issues/15339
|
|
type A = Annotated[
|
|
str, Foo(lorem='ipsum')
|
|
]
|
|
type B = Annotated[
|
|
int, lambda a=1: ...
|
|
]
|
|
type C = Annotated[
|
|
int, lambda a: ..., lambda a=1: ...
|
|
]
|