Skip to content

Latest commit

 

History

History
115 lines (91 loc) · 1.8 KB

File metadata and controls

115 lines (91 loc) · 1.8 KB

Test for global variables for case when running without ignore-global-vars.

Constants and Variable Assignments

MY_CONSTANT = 42  # insert
MY_OTHER_CONSTANT = "hello"  # insert

Debug Flag Assignment

DEBUG = True  # insert

Global vs. Local Variable Scope

MY_CONSTANT = 42  # insert
global_var = "hello"

def foo():
    local_var = 1  # insert

Constants with Type Hints

MY_CONSTANT: typing.Final = 42
MY_OTHER_CONSTANT = "hello"  # insert

Constants with Explicit Typing

MY_CONSTANT: int = 42  # insert
MY_OTHER_CONSTANT = "hello"  # insert

Constant Shadowing in Function Scope

MY_CONSTANT = 42  # insert

def foo():
    MY_CONSTANT = 1  # insert
    local_var = 2  # insert

Union Types for Constants

FRUIT = Apple | Banana  # insert

Code Examples with Header Improvements

Unchanged Global Assignment

global_var = 42

Simple Assignment

myVar = "hello"

Constant Assignment

A = 42

Constants with Global Statement

MY_CONSTANT = 42

def foo():
    global MY_CONSTANT
    MY_CONSTANT = 1

Constants with Global Declaration

from foo import MY_CONSTANT
MY_CONSTANT = 42

Final Assignment for Constants

a: typing.Final = 1

TypeVar Declaration for Generics

_T = typing.TypeVar("_T")

Final TypeVar Declaration

_T: typing.Final = typing.TypeVar("_T")

ParamSpec Declaration for Function Generics

_P = typing.ParamSpec("_P")

Final ParamSpec Declaration

_P: typing.Final = typing.ParamSpec("_P")

Union Types for Variables

Fruit = Apple | Banana

String Assignment for Constants

A = "ParamSpec"