def func(a: Union[str, int]) -> None:
Type System & Annotations

Meaning

Defines a function named func that accepts a parameter a which can be either a string or an integer and returns None, indicating the function performs side effects.

Primary Function

Defines a function that accepts a union of str and int and performs side‑effects without returning a value.

Communicative Purpose

Declare a function capable of handling either string or integer inputs for side‑effectful processing.

Pattern

def <func>(<param>: Union[str, int]) -> None:

Core Structure

def <func>(<param>: Union[str, int]) -> None:

Função primária

Defines a function that accepts a union of str and int and performs side‑effects without returning a value.

Propósito comunicativo

Declare a function capable of handling either string or integer inputs for side‑effectful processing.

Situações de gatilho

When a function needs to accept either textual or numeric input and produce side effects such as logging, printing, or modifying external state.

Contextos

Used in Python code where flexible input types are needed, e.g., CLI argument parsers, data processing pipelines, API handlers.

Padrão

def <func>(<param>: Union[str, int]) -> None:

Estrutura central

def <func>(<param>: Union[str, int]) -> None:

Slots de substituição

func, param

Colocados típicos

  • Union
  • str
  • int
  • None
  • def
  • ->
  • :

Substituições comuns

  • str|int
  • float
  • bool
  • List[int]

Erros comuns

Forgetting to import Union from typing (Python <3.10), forgetting to handle both str and int branches, accidentally returning a value despite the -> None annotation.

Similar / contraste

def func(a: str) -> None:, def func(a: int) -> None:, def func(a: Union[str, int]) -> int:

Interferências

Confusing Union with union types in other languages; neglecting to handle both possible types leading to runtime errors.

Família do chunk

  • function definitions
  • union types
  • type annotations

Nuance

The signature indicates the function accepts either a string or an integer but does not specify what it does with them; actual behavior depends on the function body.

Efeito pragmático

Signals to readers that the function is designed to accept flexible input types while performing side effects and returning no value.

Dica de memória

Function that takes a string or integer and does something with it.

Nota

Requires importing Union from typing for Python <3.10; in Python 3.10+ the union can be written as str | int.

Upgrade path

def func(a: Union[str, int]) -> ReturnType:

Tipo de construção: function_definitionTag de espaçamento: Short-term

Log in to save chunks.