Skip to content

Comments

swev-id: astropy__astropy-8707 — Accept bytes in Header.fromstring/Card.fromstring#103

Open
casey-brooks wants to merge 1 commit intoastropy__astropy-8707from
feature/bytes-support-fromstring-8707
Open

swev-id: astropy__astropy-8707 — Accept bytes in Header.fromstring/Card.fromstring#103
casey-brooks wants to merge 1 commit intoastropy__astropy-8707from
feature/bytes-support-fromstring-8707

Conversation

@casey-brooks
Copy link

Summary

  • allow Header.fromstring and Card.fromstring to accept bytes input decoded via strict ASCII
  • document the accepted input types and decoding behavior in both docstrings
  • add regression tests covering str/bytes success paths and UnicodeDecodeError on non-ASCII input

Testing

  • .venv/bin/flake8 --select=E9,F63,F7,F82 astropy/io/fits/header.py astropy/io/fits/card.py astropy/io/fits/tests/test_header.py
  • LD_LIBRARY_PATH=/nix/store/wffgswxkp55xi14jy63rjsnfvl2qvmxy-gcc-14.3.0-lib/lib .venv/bin/pytest astropy/io/fits/tests/test_header.py -k "card_fromstring_accepts_bytes or card_fromstring_bytes_strict_ascii or header_fromstring_accepts_bytes or header_fromstring_bytes_strict_ascii"

Fixes #92

@casey-brooks casey-brooks requested a review from a team December 18, 2025 16:12
@casey-brooks
Copy link
Author

Test & Lint Summary

  • .venv/bin/flake8 --select=E9,F63,F7,F82 astropy/io/fits/header.py astropy/io/fits/card.py astropy/io/fits/tests/test_header.py
  • LD_LIBRARY_PATH=/nix/store/wffgswxkp55xi14jy63rjsnfvl2qvmxy-gcc-14.3.0-lib/lib .venv/bin/pytest astropy/io/fits/tests/test_header.py -k "card_fromstring_accepts_bytes or card_fromstring_bytes_strict_ascii or header_fromstring_accepts_bytes or header_fromstring_bytes_strict_ascii" (4 passed, 150 deselected)

Copy link

@noa-lucent noa-lucent left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great. The new byte-handling logic decodes strictly before entering existing parsing paths, and the TypeError guard keeps the API precise. Added tests cover both happy paths and the UnicodeDecodeError/TypeError branches. Docstrings clearly explain the new behavior and contrast with Header.fromfile.

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.

2 participants