From 25321329674bfde4ba45189ca67519a3a3e1246f Mon Sep 17 00:00:00 2001 From: Chris Markiewicz Date: Tue, 24 Sep 2024 19:56:00 -0400 Subject: [PATCH] sty: Apply UP007, UP012 This is safe since we use from __future__ import annotations. --- nibabel/nifti1.py | 14 +++++++------- nibabel/tests/test_nifti1.py | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/nibabel/nifti1.py b/nibabel/nifti1.py index 3ad0ec938..180f67cca 100644 --- a/nibabel/nifti1.py +++ b/nibabel/nifti1.py @@ -325,15 +325,15 @@ class NiftiExtension(ty.Generic[T]): """ code: int - encoding: ty.Optional[str] = None + encoding: str | None = None _content: bytes - _object: ty.Optional[T] = None + _object: T | None = None def __init__( self, - code: ty.Union[int, str], + code: int | str, content: bytes = b'', - object: ty.Optional[T] = None, + object: T | None = None, ) -> None: """ Parameters @@ -565,9 +565,9 @@ class Nifti1DicomExtension(Nifti1Extension[DicomDataset]): def __init__( self, - code: ty.Union[int, str], - content: ty.Union[bytes, DicomDataset, None] = None, - parent_hdr: ty.Optional[Nifti1Header] = None, + code: int | str, + content: bytes | DicomDataset | None = None, + parent_hdr: Nifti1Header | None = None, ) -> None: """ Parameters diff --git a/nibabel/tests/test_nifti1.py b/nibabel/tests/test_nifti1.py index ec4b8674e..a3626f568 100644 --- a/nibabel/tests/test_nifti1.py +++ b/nibabel/tests/test_nifti1.py @@ -1239,7 +1239,7 @@ def test_extension_content_access(): assert ext.text == '123' # Test that encoding errors are caught - ascii_ext = Nifti1Extension('comment', 'hôpital'.encode('utf-8')) + ascii_ext = Nifti1Extension('comment', 'hôpital'.encode()) ascii_ext.encoding = 'ascii' with pytest.raises(UnicodeDecodeError): ascii_ext.text