Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@tallamjr
Copy link
Owner

Resolves critical code safety and correctness issues identified by Ruff linting whilst configuring pre-commit to ignore low-priority style rules.

Critical Fixes

Code Safety & Correctness

  • Add exception chaining (from err) for better debugging (B904: 4 fixes)
  • Replace unsafe type() == comparisons with isinstance() (E721: 14 fixes)
  • Use is not None instead of != None (E711: 2 fixes)
  • Implement missing download_file_from_google_drive() function (F821: 1 fix)
  • Fix loop variable shadowing issues (B020: 1 fix)
  • Rename variable shadowing Python builtin (A001: 1 fix)
  • Specify ImportError instead of bare except (E722: 1 fix)

API Exposure

  • Add 16 missing imports to __all__ in package __init__.py files (F401 fixes)
  • Ensures proper public API exposure for imports

Configuration

Updated .pre-commit-config.yaml to ignore low-priority linting rules:

  • Style preferences (PT, N, E501, E731)
  • Minor best practices (A001/A002, UP008/UP036)
  • Non-critical bugbear warnings (B007, B008, B017, B020, B028)
  • Import ordering (E402)
  • Unused/undefined variables in tests/notebooks (F841, F811, F821)

Rationale: Focus pre-commit checks on critical code safety issues rather than style
preferences, whilst maintaining code functionality and test coverage.

Testing

  • All 202 tests passing
  • Pre-commit hooks pass cleanly

References

Pre-commit Configuration:

Closes #4

Error mostly caught by ruff at the moment and types will be check with
ty at a later time but it is not production ready at this time.

References:
  - https://github.com/astral-sh/ty
Update Ruff configuration to use 88 character line length, maintaining
consistency with Black's default formatting style.
Replace incorrect 'TypedDict | None' annotation with 'dict | None' for
the all_transforms attribute. TypedDict is a class for defining typed
dictionary structures, not a type annotation itself.

This change resolves TypeError when importing tonic module:
"TypeError: unsupported operand type(s) for |: 'function' and 'NoneType'"

Additional changes from 'pre-commit run --all-files':
- Replace Optional[T] with T | None (PEP 604)
- Replace Union[T, U] with T | U (PEP 604)
- Replace Tuple with tuple (PEP 585)
- Move collections.abc imports to correct location
- Add strict=False to zip() calls for Python 3.10+ compatibility
- Auto-fix formatting and linting issues across all files

All 202 tests pass after these changes.
Fix high-priority code safety and correctness issues:

- B904: Add exception chaining to preserve debugging context (3 fixes)
- E721: Replace type() == with isinstance() for proper type checking (14 fixes)
- E711: Use 'is not None' instead of '!= None' (2 fixes)
- F821: Implement missing download_file_from_google_drive() function (1 fix)
- B020: Fix loop variable shadowing in cached_dataset.py (1 fix)
- A001: Rename 'zip' variable to avoid shadowing builtin (1 fix)

All changes verified with pytest (202 tests passing).

References:
#4
Add missing imports to __all__ for proper API exposure (F401 fixes).
Configure pre-commit to ignore B008 and F841 errors.

All changes verified with pytest (202 tests passing).

References:
#4
Ignore style and best practice rules that are not critical for code safety:
- PT: Pytest style improvements
- A001/A002: Variable shadowing builtins
- E402: Import ordering
- E711/E731: Style violations
- UP008/UP036: Outdated Python patterns
- B007/B017/B028: Additional bugbear warnings
- C411/C419: Unnecessary list operations

Focus pre-commit checks on critical code safety issues only.

References:
#4
- E722: Specify ImportError instead of bare except in collation.py
- B904: Add exception chaining in dsec.py for pypng import error

All changes verified with pytest (202 tests passing).

References:
#4
@tallamjr tallamjr merged commit 8f95aec into develop Oct 21, 2025
44 of 48 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Resolve Ruff linting and formatting violations

2 participants