Misc mypy fixes/clean-up by peterjc · Pull Request #5248 · biopython/biopython · GitHub
Skip to content

Misc mypy fixes/clean-up#5248

Open
peterjc wants to merge 3 commits into
biopython:masterfrom
peterjc:mypy-misc
Open

Misc mypy fixes/clean-up#5248
peterjc wants to merge 3 commits into
biopython:masterfrom
peterjc:mypy-misc

Conversation

@peterjc

@peterjc peterjc commented Jun 25, 2026

Copy link
Copy Markdown
Member
  • 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.)

This addresses most of the issues flagged by running mypy 1.16.1 which is in the pre-commit configuration but not run on the pre-commit CI due to time concerns. It seems some recent work had not been validated with the mypy setup.

There is still one issue in Bio/PDB/Atom.py with some mixing of single-element-arrays vs booleans I think:

$ mypy --version
mypy 1.16.1 (compiled: yes)
$ mypy Bio/ BioSQL/
Bio/PDB/Atom.py: note: In member "strictly_equals" of class "Atom":
Bio/PDB/Atom.py:290:13: error: Incompatible return value type (got
"numpy.bool[builtins.bool] | Any | builtins.bool", expected "builtins.bool")  [return-value]
                self.name == other.name
                ^
Bio/PDB/Atom.py:291:28: error: Argument 1 to "isclose" has incompatible type "float | None";
expected "complex | number[Any, int | float | complex] | numpy.bool[builtins.bool]"  [arg-type]
                and np.isclose(self.bfactor, other.bfactor)
                               ^~~~~~~~~~~~
Bio/PDB/Atom.py:291:42: error: Argument 2 to "isclose" has incompatible type "float | None";
expected "complex | number[Any, int | float | complex] | numpy.bool[builtins.bool]"  [arg-type]
                and np.isclose(self.bfactor, other.bfactor)
                                             ^~~~~~~~~~~~~
Bio/PDB/Atom.py:292:28: error: Argument 1 to "isclose" has incompatible type "float | None";
expected "complex | number[Any, int | float | complex] | numpy.bool[builtins.bool]"  [arg-type]
                and np.isclose(self.occupancy, other.occupancy)
                               ^~~~~~~~~~~~~~
Bio/PDB/Atom.py:292:44: error: Argument 2 to "isclose" has incompatible type "float | None";
expected "complex | number[Any, int | float | complex] | numpy.bool[builtins.bool]"  [arg-type]
                and np.isclose(self.occupancy, other.occupancy)
                                               ^~~~~~~~~~~~~~~
Found 5 errors in 1 file (checked 298 source files)

Found while testing with zuban as a possible faster alternative to mypy: https://github.com/zubanls/zuban/

peterjc added 3 commits June 25, 2026 14:01
Solves this typing complaint:

Bio/Align/__init__.py: note: In member "from_alignments_with_same_reference" of class "Alignment":
Bio/Align/__init__.py:1253:27: error: Incompatible types in assignment (expression has type
"ndarray[Any, Any]", variable has type "list[list[Any]]")  [assignment]
            msa_coordinates = np.array(msa_coordinates).transpose()
                              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Solves these three with mypy 1.16.1:

Bio/PDB/Atom.py: note: In member "set_sigatm" of class "Atom":
Bio/PDB/Atom.py:333:29: error: Incompatible types in assignment (expression has type
"ndarray[tuple[Any, ...], dtype[Any]] | None", variable has type "None")  [assignment]
            self.sigatm_array = sigatm_array
                                ^~~~~~~~~~~~
Bio/PDB/Atom.py: note: In member "set_siguij" of class "Atom":
Bio/PDB/Atom.py:341:29: error: Incompatible types in assignment (expression has type
"ndarray[tuple[Any, ...], dtype[Any]] | None", variable has type "None")  [assignment]
            self.siguij_array = siguij_array
                                ^~~~~~~~~~~~
Bio/PDB/Atom.py: note: In member "set_anisou" of class "Atom":
Bio/PDB/Atom.py:349:29: error: Incompatible types in assignment (expression has type
"ndarray[tuple[Any, ...], dtype[Any]] | None", variable has type "None")  [assignment]
            self.anisou_array = anisou_array
@codecov

codecov Bot commented Jun 25, 2026

Copy link
Copy Markdown

@peterjc

peterjc commented Jun 25, 2026

Copy link
Copy Markdown
Member Author

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