Skip to content

fix: Deprecate query_letters and database_letters attributes#5168

Open
A404coder wants to merge 6 commits intobiopython:masterfrom
A404coder:fix/issue-1000-deprecate-attributes
Open

fix: Deprecate query_letters and database_letters attributes#5168
A404coder wants to merge 6 commits intobiopython:masterfrom
A404coder:fix/issue-1000-deprecate-attributes

Conversation

@A404coder
Copy link
Copy Markdown

@A404coder A404coder commented Feb 24, 2026

  • I hereby agree to dual licence this and any previous contributions under both
    the Biopython License Agreement AND the BSD 3-Clause License.

  • I have read the CONTRIBUTING.rst file, have run pre-commit
    locally, and understand that continuous integration checks will be used to
    confirm the Biopython unit tests and style checks pass with these changes.

  • I have added my name to the alphabetical contributors listings in the files
    NEWS.rst and CONTRIB.rst as part of this pull request, am listed
    already, or do not wish to be listed. (This acknowledgement is optional.)

Closes #1000

Changes

  • Convert query_letters and database_letters to properties in Header class with deprecation warnings via BiopythonParserWarning
  • Use _query_letters directly in parser internals to avoid triggering warnings during XML parsing
  • Update all tests in test_NCBIXML.py and test_NCBI_qblast.py to use query_length instead of query_letters
  • Add tests confirming deprecation warnings are raised for both query_letters and database_letters
  • Add deprecation entry to DEPRECATED.rst
  • Add contributor name to NEWS.rst and CONTRIB.rst

Context

The issue has been open since 2016. The XML parser sets both query_letters and query_length, as well as database_letters and database_length. This change helps users migrate to the preferred attributes while maintaining backward compatibility.

Testing

  • All 24 existing NCBIXML tests pass with query_length replacing query_letters
  • 2 new tests verify BiopythonParserWarning is raised when accessing deprecated attributes
  • No warnings triggered during normal XML parsing (parser uses private attributes internally)

…ibutes

- Convert query_letters and database_letters to properties with deprecation warnings
- Maintain backward compatibility - attributes still work but emit warnings
- Direct users to use query_length and database_length instead
- Addresses issue biopython#1000 opened in 2016
Comment thread Bio/Blast/NCBIXML.py
@peterjc
Copy link
Copy Markdown
Member

peterjc commented Feb 25, 2026

This is what I expected on the code side, which is good.

You've ignored the pull request template - please address
that.

There should be a test accessing the .query_letters and .database_letters properties and confirming the warning is present.

Otherwise, please update the tests to silence the new BiopythonParserWarning: The query_letters attribute is deprecated. Please use query_length instead. etc messages by using the preferred .query_length.

Also please add an entry to the DEPRECATED file.

@A404coder
Copy link
Copy Markdown
Author

Thanks for the detailed review! I've addressed the feedback in the latest commit:

  • Deprecation warning tests: Added test_deprecated_query_letters and test_deprecated_database_letters that verify BiopythonParserWarning is raised when accessing these attributes.
  • Updated existing tests: Replaced all record.query_letters usages with record.query_length in test_NCBIXML.py (19 occurrences) and test_NCBI_qblast.py (2 occurrences) to silence the deprecation warnings.
  • DEPRECATED.rst: Added an entry for the deprecation of query_letters and database_letters.
  • Parser internals: Changed the parser to use _query_letters directly instead of going through the public property, so no warnings are triggered during XML parsing.

I'll also fill in the PR template shortly. All tests pass locally.

…th, add DEPRECATED entry

- Use _query_letters internally in parser to avoid triggering deprecation warnings during XML parsing
- Replace query_letters with query_length in test_NCBIXML.py and test_NCBI_qblast.py
- Add tests confirming BiopythonParserWarning for deprecated query_letters and database_letters
- Add Bio.Blast.NCBIXML entry to DEPRECATED.rst
@A404coder A404coder force-pushed the fix/issue-1000-deprecate-attributes branch from 7384662 to d639795 Compare February 25, 2026 21:50
Comment thread Bio/Blast/NCBIXML.py
# query_length properties (as in the plain text parser, see
# Bug 2176 comment 12):
self._blast.query_length = self._blast.query_letters
self._blast.query_length = self._blast._query_letters
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You might update the comment just below this?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Good catch! Updated the comment in the latest commit — removed the old "hack" / "transition period" wording and replaced it with a note that query_letters is now deprecated in favour of query_length.

@peterjc
Copy link
Copy Markdown
Member

peterjc commented Feb 27, 2026

By eye this looks good - something off in the formatting, black reports:

would reformat Tests/test_NCBIXML.py
would reformat Tests/test_NCBI_qblast.py

Fix formatting issues flagged by CI (black reports would reformat
test_NCBIXML.py and test_NCBI_qblast.py).
Address review comment from peterjc - the old comment mentioned
recording query length as both query_letters and query_length with
a future deprecation plan. Since query_letters is now deprecated,
update the comment to reflect the current state.
@A404coder
Copy link
Copy Markdown
Author

Thanks for catching the formatting issue! I've run black on both test files and also updated the outdated comment about the query_letters/query_length transition (as you suggested in the inline review). All should be clean now.

Comment thread Bio/Blast/NCBIXML.py Outdated
@peterjc
Copy link
Copy Markdown
Member

peterjc commented Mar 2, 2026

Ah: "Co-Authored-By: Claude Sonnet 4.6 noreply@anthropic.com"

We (Biopython) don't yet have a formal policy about this yet, but that is becoming more pressing. See also my blog post from late last year: https://blastedbio.blogspot.com/2025/11/thoughts-on-generative-ai-contributions.html

I was just involved in a conversation earlier today that "Good first issue" tagged issues (or their equivalents) ought to be explicitly reserved for humans, and not AI agents. Most projects (Biopython too) have deliberately left these "low hanging fruit" which the maintainers could easily do themselves, as real-world tasks to train beginners (even though this will often cost the maintainers more time). This is as an investment for the future (those people are then more likely to make further more valuable contribution here or elsewhere).

At least in this case the scope and nature of the changes is such that we don't need to worry about copyright issues.

The TODO has been addressed in this PR — database_letters is now
deprecated. Remove the stale comment as suggested by reviewer.
@A404coder A404coder force-pushed the fix/issue-1000-deprecate-attributes branch from 632fbf1 to 313f625 Compare March 3, 2026 12:24
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.

Deprecate record.database_letters, record.query_letters

2 participants