Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Enable flake8-bugbear (B) and review further ruff rule sets

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

I maintainer di solito rispondono entro 1 giorno

@ryan-kipawa ci sta già lavorando.

Dal 9/10/2026.

  • #74 di @ryan-kipawa — aperta

Valutazione

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

Direzione di ricerca

Start by checking linked PR #74, since it may already cover this work. The rule set is in pyproject.toml; add B and ignore B008. The five delete-value setters in mikecore/DfsBuilder.py (around lines 124-160) need self.__CheckBuildStage1() with the parentheses added, and tests/examples_dfsu.py (line 297) and tests/test_dfsu_file.py (line 1264) hold the two stray expressions. Done when ruff reports no B findings, the pre-commit hooks pass, and a new test shows that setting a delete value after CreateFile raises an error.

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

Descrizione

Why

Five DfsBuilder delete-value setters never run their build-stage check, because the call is missing its parentheses:

https://github.com/DHI/mikecore-python/blob/257982a31c1e131b73df32cd852827e72581269d/mikecore/DfsBuilder.py#L132-L134

def SetDeleteValueDouble(self, value):
    self.__CheckBuildStage1          # looks the method up, never calls it
    self.FileInfo.DeleteValueDouble = value

The same line is in SetDeleteValueFloat, SetDeleteValueByte, SetDeleteValueInt and SetDeleteValueUnsignedInt (L124, L133, L142, L151, L160). Every other setter calls self.__CheckBuildStage1(). So a delete value can be changed after CreateFile without an error, after the header has already been written.

The same rule finds two more bugs in the tests:

  • tests/examples_dfsu.py#L297: a bare topLayerOffset, left over from a C# declaration, reads a local before it is assigned. So ExtractDfsu2DLayerFrom3D raised NameError on every call. It is fixed in #66.
  • tests/test_dfsu_file.py#L1264: a bare Assert.IsTrue that is never called, so that line asserts nothing.

None of our checks reports these. Ruff runs only E4, E7, E9, F and UP (pyproject.toml), and none of those rules looks at expressions whose value is discarded. A type checker (pyrefly, #66) accepts an uncalled bound method as a valid expression. flake8-bugbear's B018 (useless expression) finds exactly these 7 lines and nothing else.

Proposal

Add the bugbear rules (B) to ruff's select, ignoring B008, and fix what they report. On master that is 29 findings:

Rule Hits Finding
B018 useless expression 7 The 5 setters and the 2 test lines above. Real bugs.
B017 pytest.raises(Exception) 4 tests/test_dfsbuilder.py. These pass on any error, including one caused by a bug. Add match=.
B904 raise in except without from 11 SetNodes in both builders and MeshFile. Adding from err keeps the cause in the traceback.
B007 unused loop variable 3 Rename to _j / _i.
B008 call in a default argument 4 Not bugs (DfsParameters() is never mutated, np.float32 is immutable), so ignore the rule. B006 (mutable defaults) still applies.

The rules with no findings today are still worth having in a codebase ported from C#: B015 (a comparison used as a statement, where an assert was meant), B011 (assert False), B023 (a closure over a loop variable), B006 (a mutable default argument) and B905 (zip() without strict=, which #66's new tests would trip).

Once B is in, other rule sets could be reviewed the same way, each with its findings on master. Candidates are PT (pytest style), SIM, and PL errors (PLE).

Done when

  • select includes B, B008 is ignored with a reason, and uvx pre-commit run --all-files passes.
  • The 5 setters call self.__CheckBuildStage1(), with a test that setting a delete value after CreateFile raises an error.
Lingua principale
Python
Stelle
5
Fork
1
Merge medio
9h 31m
PR unite (30g)
8

Preparare l'ambiente

  • Include un Dockerfile o un file Docker Compose
  • Nessun modello di pull request
  • Nessuna guida per i contributori

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 DHI/mikecore-python

Tutte le issue di DHI/mikecore-python

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.