1414 Union ,
1515)
1616
17- import numpy as np
17+ import numpy as np # pylint: disable=unused-import
1818
1919import boost_histogram
2020
@@ -31,10 +31,9 @@ def _isstr(value: Any) -> bool:
3131
3232 if isinstance (value , (str , bytes )):
3333 return True
34- elif hasattr (value , "__iter__" ):
34+ if hasattr (value , "__iter__" ):
3535 return all (_isstr (v ) for v in value )
36- else :
37- return False
36+ return False
3837
3938
4039def _opts (** kwargs : bool ) -> Set [str ]:
@@ -87,7 +86,7 @@ def __init__(
8786 raise KeyError (
8887 "Cannot provide metadata by keyword and __dict__, use __dict__ only"
8988 )
90- elif __dict__ is not None :
89+ if __dict__ is not None :
9190 self ._ax .metadata = __dict__
9291 elif metadata is not None :
9392 self ._ax .metadata ["metadata" ] = metadata
@@ -112,14 +111,11 @@ def index(self, value: Union[float, str]) -> int:
112111 Return the fractional index(es) given a value (or values) on the axis.
113112 """
114113
115- if not _isstr (value ):
116- return self ._ax .index (value ) # type: ignore[no-any-return]
117- else :
118- raise TypeError (
119- "index({value}) cannot be a string for a numerical axis" .format (
120- value = value
121- )
122- )
114+ if _isstr (value ):
115+ msg = f"index({ value } ) cannot be a string for a numerical axis"
116+ raise TypeError (msg )
117+
118+ return self ._ax .index (value ) # type: ignore[no-any-return]
123119
124120 def value (self , index : float ) -> float :
125121 """
@@ -486,7 +482,8 @@ def _repr_args_(self) -> List[str]:
486482 if len (self ) > 20 :
487483 ret = [repr (self .edges )]
488484 else :
489- ret = ["[{}]" .format (", " .join (format (v , "g" ) for v in self .edges ))]
485+ args = ", " .join (format (v , "g" ) for v in self .edges )
486+ ret = [f"[{ args } ]" ]
490487
491488 if self .traits .growth :
492489 ret .append ("growth=True" )
@@ -670,17 +667,15 @@ def index(self, value: Union[float, str]) -> int:
670667
671668 if _isstr (value ):
672669 return self ._ax .index (value ) # type: ignore[no-any-return]
673- else :
674- raise TypeError (
675- "index({value}) must be a string or iterable of strings for a StrCategory axis" .format (
676- value = value
677- )
678- )
670+
671+ msg = f"index({ value } ) must be a string or iterable of strings for a StrCategory axis"
672+ raise TypeError (msg )
679673
680674 def _repr_args_ (self ) -> List [str ]:
681675 "Return inner part of signature for use in repr"
682676
683- ret = ["[{}]" .format (", " .join (repr (c ) for c in self ))]
677+ args = ", " .join (repr (c ) for c in self )
678+ ret = [f"[{ args } ]" ]
684679 ret += super ()._repr_args_ ()
685680 return ret
686681
@@ -732,7 +727,8 @@ def __init__(
732727 def _repr_args_ (self ) -> List [str ]:
733728 "Return inner part of signature for use in repr"
734729
735- ret = ["[{}]" .format (", " .join (format (c , "g" ) for c in self ))]
730+ args = ", " .join (format (c , "g" ) for c in self )
731+ ret = [f"[{ args } ]" ]
736732 ret += super ()._repr_args_ ()
737733 return ret
738734
0 commit comments