Parameter loader turns __pycache__ directories into parameter nodes

Aperta
#638 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

@anth-volk ci sta già lavorando.

Dal 29/10/2026.

  • #637 di @anth-volk — aperta

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Ferma
Stack tecnologico
python
Ambito
backend

Direzione di ricerca

Read policyengine_core/parameters/parameter_node.py, focusing on the subdirectory branch and the existing EXCLUDED_PARAMETER_CHILD_NAMES checks. Reproduce the issue with a parameter directory containing __pycache__ or a hidden subdirectory, then check the parameter tree excludes both. A linked pull request (#637) is already open.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

bug

Problem

ParameterNode(directory_path=...) makes every subdirectory of a parameter directory a child node. EXCLUDED_PARAMETER_CHILD_NAMES in policyengine_core/parameters/parameter_node.py already lists __pycache__, but only the YAML-file branch and the inline-data branch check it. The subdirectory branch does not, so a __pycache__ directory becomes an empty <directory>.__pycache__ node.

Python writes __pycache__ into a parameter directory whenever that directory is also a Python package that gets imported. The loaded parameter tree therefore depends on whether bytecode has been written to disk.

Effect

policyengine-us 2.2.1 has six parameter directories that hold only an __init__.py and CSV files, and US variable modules import them:

  • gov.hhs.medicaid.geography
  • gov.hud.fmr
  • gov.hud.income_limits
  • gov.hud.payment_standards
  • gov.states.fl.doe.sr.rates.reimbursement
  • gov.states.tx.twc.ccs.payment.rates_expanded_age_groups

Without bytecode caches, each of these nodes has no children. With caches, each has one empty __pycache__ child. policyengine.py skips parameter nodes with no children, so its US parameter-node count changes by 6 depending on whether the caches exist: 28,559 without them and 28,565 with them, measured with policyengine-us 2.2.1 and policyengine-core 3.33.3.

The Public API's v2 catalog takes its parameter nodes from policyengine.py. Its exact-count integration test (tests/integration/test_v2_catalog_installed.py) reports 29,361 parameter nodes on macOS with PYTHONDONTWRITEBYTECODE=1 and 29,367 elsewhere. The count follows the files on disk, not the environment variable: once caches have been written, for example by pip install's bytecode compilation or an earlier run, PYTHONDONTWRITEBYTECODE=1 still gives the higher count.

Hidden directories have the same problem. A .ipynb_checkpoints directory inside a parameter directory loads copies of the YAML files next to it as extra parameters, under names that are not valid dotted paths.

Expected

The loaded parameter tree should not depend on bytecode caches or on hidden tool directories. Subdirectories named __pycache__, and hidden subdirectories, should not become parameter nodes.

Lingua principale
Python
Stelle
22
Fork
30
Merge medio
4g 20h
PR unite (30g)
26

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di PolicyEngine/policyengine-core

Tutte le issue di PolicyEngine/policyengine-core

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.