주제: python
-
지원 종료 이후의 Python 3.10: 런타임 찾기와 환경 재구축
Python 업스트림 수명 주기 표는 Python 3.10의 지원 종료일을 2026년 10월 1일로 기록합니다. 서비스, 가상 환경, 이미지가 실제 사용하는 인터프리터를 목록으로 정리한 뒤, 지원 중인 브랜치에서 각 애플리케이션을 다시 구축하고 테스트합니다.
-
파이썬 명령줄 도구 설계하기: argparse, main(), 종료 코드
인터페이스는 콘솔 스크립트로 등록한 main(argv) -> int 함수 안에 두고, argparse의 type과 choices로 값을 검증하고, 종료 코드 관례(0은 성공, 2는 사용법 오류, 1은 그 외 실패, sysexits 코드는 문서화한 경우에만)를 따르고, 결과는 stdout에 진단 메시지는 stderr에 남기고, SIGINT와 broken pipe를 처리합니다.
-
중앙값, 백분위수, 비율에 대한 신뢰구간을 부트스트랩으로 구하기
원본 관측값에서 복원추출로 여러 번 재표본을 뽑아 매번 통계량을 계산하고, 그렇게 얻은 분포에서 구간을 읽어냅니다. 이 방법은 교과서 공식이 없는 중앙값, 백분위수, 비율, 그리고 이들의 차이에 대해서도 불확실성을 제공합니다. 방법, 재표본 횟수, 표본 크기를 함께 보고해야 하며, 소표본의 극단적인 백분위수에는 이 방법을 신뢰해서는 안 됩니다.
-
npm·PyPI 게시 신원을 승인된 릴리스 아티팩트에 연결하기
OIDC trusted publishing은 저장된 게시 토큰을 없애지만, 보안은 여전히 권한을 부여받은 워크플로에 달려 있습니다. 빌드와 게시를 분리하고 승인 절차를 보호하며, 출처 증명을 악성 코드 판정으로 받아들이는 대신 아티팩트의 신원을 검증해야 합니다.
-
Property-based testing with generated inputs
Instead of hand-picked examples, a property-based test states an invariant and lets a library generate many inputs, shrinking failures to minimal counterexamples; Hypothesis is the reference implementation for Python.
-
Context managers in Python: guaranteeing clean-up
The with statement runs __enter__ and __exit__ around a block so that files, locks and connections are released even when an exception occurs; contextlib.contextmanager turns a generator into one.
-
Docstrings that tools and readers can use
PEP 257 defines where docstrings go and how they are formatted; a consistent style (Google or NumPy) with a one-line summary, argument and return descriptions and raised exceptions makes them usable by readers, editors and documentation generators.
-
Floating-point numbers: why 0.1 + 0.2 is not 0.3
Binary floating point represents most decimal fractions approximately, so arithmetic accumulates rounding error; compare with tolerances, sum carefully, use integers or decimal types for money and counts, and print with enough digits to round-trip.
-
Loading YAML safely
Full YAML loaders can instantiate arbitrary objects from tagged nodes; always use a safe loader, pin the YAML version semantics, and validate the result against a schema before use.
-
Glob pattern dialects: what * and ** mean in .gitignore, .dockerignore, bash, Python and GitHub Actions
The same star and double-star characters mean different things depending on where the pattern is evaluated: a slash-less .gitignore pattern matches at every depth while the same line in .dockerignore only matches at the context root, bash's globstar recursion is opt-in, and Python's fnmatch is not even path-aware.
-
When asyncio helps and when it does not
asyncio runs many I/O-bound tasks on one thread by suspending at await points; it does not speed up CPU-bound code, and blocking calls inside coroutines stall the whole loop.
-
Automated formatting and linting as a team contract
Delegating layout to a formatter and mechanical checks to a linter removes style debates from review; EditorConfig, PEP 8 and tools such as Ruff show how the contract can be encoded in the repository.
-
Protocol classes: structural typing for duck-typed Python
A typing.Protocol declares the methods and attributes a consumer needs; any object that has them satisfies the type without inheriting from it. Define protocols next to the code that depends on them, keep them minimal, and use runtime_checkable only where isinstance is really needed.
-
Finding a memory leak with tracemalloc snapshots
Start tracing early with PYTHONTRACEMALLOC or tracemalloc.start(nframe), take a snapshot after warm-up and another after N iterations, filter import noise, and read compare_to(..., 'lineno') for lines whose size grows proportionally to N; switch to 'traceback' grouping to see the callers.
-
Money and other exact quantities: use Decimal, not float
Binary floating point cannot represent most decimal fractions exactly, so sums of prices drift; the decimal module provides exact decimal arithmetic with explicit rounding, and integers in minor units are an alternative.
-
Choosing between threads, processes and asyncio for a Python workload
Classify the hot path first: waiting on I/O suits asyncio (many connections, async libraries) or a thread pool (few blocking calls); pure-Python CPU work needs processes or a free-threaded build; native code that releases the GIL can use threads. Bound every pool, choose the process start method explicitly and write the shutdown path.
-
Dataclasses for plain records
dataclasses generate __init__, __repr__ and equality from annotated fields; frozen dataclasses give immutable value objects, slots reduce memory, and field(default_factory=...) avoids shared mutable defaults.
-
At what workload does the free-threaded CPython build beat a process pool for a mixed I/O and CPU service?
Open question: the free-threaded build removes the GIL but adds single-threaded overhead and may fall back to the GIL when an unprepared extension is imported, while process pools pay for pickling and memory duplication; for which CPU-to-wait ratios, working sets and core counts does a thread pool on the free-threaded build deliver more throughput per core?
-
Attempting an exercise before reading its worked solution yields better one-month recall of a language feature than reading the solution first
Hypothesis: for an engineer learning a specific language feature, such as Python's match statement, working an exercise before seeing the worked solution leads to better delayed recall and transfer than studying the solution first and then working a similar exercise; a proposed within-person test with two features, two orders and a one-month delayed test, with no result claimed.
-
asyncio cancellation: perform cleanup without swallowing CancelledError
Keep cancellation observable by the task owner while releasing resources on the interrupted path.
기계 판독 가능: JSON