Skip to content

Remove python2 guidance#9622

Open
johanste wants to merge 4 commits intoAzure:mainfrom
johanste:copilot/remove-python2-guidance
Open

Remove python2 guidance#9622
johanste wants to merge 4 commits intoAzure:mainfrom
johanste:copilot/remove-python2-guidance

Conversation

@johanste
Copy link
Member

Two sets of guideline changes: (1) remove all Python 2 compatibility guidance and update typing for a 3.9+ minimum, and (2) restrict **kwargs usage to pass-through scenarios only.

Python 2 removal & typing modernization (design.md, implementation.md)

  • Minimum version: 3.8 → 3.9
  • Removed azure-nspkg / azure-<group>-nspkg dependency requirements
  • Removed collections fallback (Python 2.7), "straddling code" PEP 484 reference, (object) base class from examples, "only need to support Python 3" qualifiers, Python 3.4/3.5 historical references
  • Added PEP 585 requirement — use list[str] not typing.List[str]
  • Added Union/Optional guidance with comment noting PEP 604 X | Y syntax for when minimum moves to 3.10+
# 3.9+
def get_things() -> list[str]: ...
def foo(x: Union[int, str]) -> Optional[str]: ...

# When minimum is 3.10+:
# def foo(x: int | str) -> str | None: ...

Keyword-only arguments over **kwargs (implementation.md, design.md, documentation.md)

  • Added MUSTNOT (python-codestyle-no-kwargs-for-arguments): **kwargs must not be used for arguments consumed by the method — use keyword-only args
  • Added MAY (python-codestyle-kwargs-passthrough): **kwargs allowed only for pass-through, must document target API(s)
  • Updated docstring requirements in both design.md and documentation.md to require documenting which API(s) receive forwarded **kwargs
  • Removed **kwargs as alternative in python-codestyle-long-args
# Yes — explicit keyword-only arguments:
def create_thing(name: str, *, size: int = 0, color: str = "blue") -> None: ...

# No — kwargs.pop pattern for consumed arguments:
def create_thing(name: str, **kwargs) -> None:
    size = kwargs.pop("size", 0)
    ...

# OK — pass-through with documented target:
def get_thing(self, name: str, **kwargs) -> "Thing":
    """Keyword arguments are passed to the HTTP pipeline.
    See https://aka.ms/azsdk/python/options.
    """
    return self._pipeline.send(request, **kwargs)

Copilot AI and others added 4 commits February 12, 2026 22:45
Co-authored-by: johanste <15110018+johanste@users.noreply.github.com>
…forwarded kwargs targets

Co-authored-by: johanste <15110018+johanste@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants