Skip to main content

prefer-pathlib-over-os-path

When a function handles filesystem paths, build them with pathlib.Path

Datos de origen

Repositorio
samugit83/cortex
Última actividad en el origen
20 de septiembre de 2026 a las 20:32
Idioma detectado de SKILL.md
inglés
Estrellas
3
Forks
1

Opciones de instalación

De forma predeterminada está seleccionado el prompt que primero revisa el origen. Puedes cambiar a un comando directo o descargar una copia local.

Revisa los archivos de origen

Lee SKILL.md y los archivos complementarios que muestra SkillsMP antes de decidir si quieres instalarlo.

Mostrando SKILL.md

SKILL.md
Instrucciones de origen · Vista previa de solo lectura
name
prefer-pathlib-over-os-path
description
When a function handles filesystem paths, build them with pathlib.Path
# Paths `pathlib.Path` reads better than string joining and carries its own helpers. 1. Take `Path` objects in signatures that accept a path, and accept `str` only at the edge where a caller hands one in. 2. Build a child path with the `/` operator: `root / "data" / "catalog.json"`. 3. Read and write through `Path.read_text()` and `Path.write_text()` with an explicit `encoding="utf-8"` rather than opening a file by hand. 4. Use `Path.resolve()` once, at the boundary, and pass the resolved path down instead of resolving it again in every function that receives it. A signature that accepts both a string and a Path should say so in its annotation (`str | Path`) so a reader knows which forms are handled.
Ver en GitHub