sphinx/tests/roots/test-ext-autodoc/target/preserve_defaults.py

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

79 lines
1.6 KiB
Python
Raw Normal View History

from __future__ import annotations
from datetime import datetime
from typing import Any
CONSTANT = 'foo'
SENTINEL = object()
2025-01-02 19:09:26 -06:00
def foo(
name: str = CONSTANT,
sentinel: Any = SENTINEL,
now: datetime = datetime.now(), # NoQA: B008,DTZ005
color: int = 0xFFFFFF,
*,
kwarg1,
kwarg2=0xFFFFFF,
) -> None:
"""docstring"""
class Class:
"""docstring"""
2025-01-02 19:09:26 -06:00
def meth(
self,
name: str = CONSTANT,
sentinel: Any = SENTINEL,
now: datetime = datetime.now(), # NoQA: B008,DTZ005
color: int = 0xFFFFFF,
*,
kwarg1,
kwarg2=0xFFFFFF,
) -> None:
"""docstring"""
@classmethod
2025-01-02 19:09:26 -06:00
def clsmeth(
cls,
name: str = CONSTANT,
sentinel: Any = SENTINEL,
now: datetime = datetime.now(), # NoQA: B008,DTZ005
color: int = 0xFFFFFF,
*,
kwarg1,
kwarg2=0xFFFFFF,
) -> None:
"""docstring"""
2025-01-02 19:09:26 -06:00
get_sentinel = lambda custom=SENTINEL: custom # NoQA: E731
"""docstring"""
class MultiLine:
"""docstring"""
# The properties will raise a silent SyntaxError because "lambda self: 1"
# will be detected as a function to update the default values of. However,
# only prop3 will not fail because it's on a single line whereas the others
# will fail to parse.
2025-01-02 19:09:26 -06:00
# fmt: off
prop1 = property(
2025-01-02 19:09:26 -06:00
lambda self: 1, doc='docstring')
prop2 = property(
2025-01-02 19:09:26 -06:00
lambda self: 2, doc='docstring'
)
2025-01-02 19:09:26 -06:00
prop3 = property(lambda self: 3, doc='docstring')
prop4 = (property
2025-01-02 19:09:26 -06:00
(lambda self: 4, doc='docstring'))
prop5 = property\
2025-01-02 19:09:26 -06:00
(lambda self: 5, doc='docstring') # NoQA: E211
# fmt: on