diff --git a/.mypy b/.mypy new file mode 100644 index 000000000..39a6b229b --- /dev/null +++ b/.mypy @@ -0,0 +1,146 @@ +pint\facets\plain\qto.py:126: error: Argument 1 to "log10" has incompatible type "Number"; expected "SupportsFloat | SupportsIndex" [arg-type] +pint\facets\plain\qto.py:127: error: Argument 1 to "log10" has incompatible type "Number"; expected "SupportsFloat | SupportsIndex" [arg-type] +pint\facets\numpy\numpy_func.py:831: error: Incompatible types in assignment (expression has type "Any | None", variable has type Module) [assignment] +pint\facets\plain\quantity.py:431: error: Incompatible return value type (got "tuple[MagnitudeT, tuple[tuple[str, float | int | Decimal | Fraction | number[Any]], ...]]", expected "tuple[MagnitudeT, tuple[tuple[str, ...]]]") [return-value] +pint\facets\plain\registry.py:246: error: Argument 1 to "__call__" of "_lru_cache_wrapper" has incompatible type "type[float] | type[Decimal] | type[Fraction]"; expected "Hashable" [arg-type] +pint\facets\plain\registry.py:251: error: Argument 1 to "ParserConfig" has incompatible type "type[float] | type[Decimal] | type[Fraction]"; expected "type[Number]" [arg-type] +pint\facets\plain\registry.py:254: error: Argument 1 to "Formatter" has incompatible type "GenericPlainRegistry[QuantityT, UnitT]"; expected "UnitRegistry | None" [arg-type] +pint\facets\plain\registry.py:312: error: Argument 2 to "PrefixDefinition" has incompatible type "int"; expected "Number" [arg-type] +pint\facets\plain\registry.py:312: note: Types from "numbers" aren't supported for static type checking +pint\facets\plain\registry.py:312: note: See https://peps.python.org/pep-0484/#the-numeric-tower +pint\facets\plain\registry.py:312: note: Consider using a protocol instead, such as typing.SupportsFloat +pint\facets\plain\registry.py:325: error: Value of type variable "TT" of "create_class_with_registry" cannot be "UnitT" [type-var] +pint\facets\plain\registry.py:325: error: Argument 1 to "create_class_with_registry" has incompatible type "GenericPlainRegistry[QuantityT, UnitT]"; expected "UnitRegistry" [arg-type] +pint\facets\plain\registry.py:326: error: Value of type variable "TT" of "create_class_with_registry" cannot be "QuantityT" [type-var] +pint\facets\plain\registry.py:326: error: Argument 1 to "create_class_with_registry" has incompatible type "GenericPlainRegistry[QuantityT, UnitT]"; expected "UnitRegistry" [arg-type] +pint\facets\plain\registry.py:353: error: Unsupported target for indexed assignment ("Handler") [index] +pint\facets\plain\registry.py:358: error: Argument 2 to "_register_adder" of "GenericPlainRegistry" has incompatible type "Callable[[CommentDefinition], CommentDefinition]"; expected "Callable[[CommentDefinition], None]" [arg-type] +pint\facets\plain\registry.py:368: error: Incompatible return value type (got "Self", expected "type[Self]") [return-value] +pint\facets\plain\registry.py:381: error: Incompatible return value type (got "QuantityT", expected "UnitT") [return-value] +pint\facets\plain\registry.py:473: error: Item "None" of "DefParser | None" has no attribute "parse_string" [union-attr] +pint\facets\plain\registry.py:475: error: Incompatible types in assignment (expression has type "ParsedStatement[ParserConfig] | Any", variable has type "str | type") [assignment] +pint\facets\plain\registry.py:475: error: Item "None" of "DefParser | None" has no attribute "iter_parsed_project" [union-attr] +pint\facets\plain\registry.py:517: error: "NamedDefinition" has no attribute "symbol" [attr-defined] +pint\facets\plain\registry.py:574: error: Item "None" of "UnitsContainer | None" has no attribute "keys" [union-attr] +pint\facets\plain\registry.py:596: error: Item "None" of "DefParser | None" has no attribute "parse_string" [union-attr] +pint\facets\plain\registry.py:598: error: Item "None" of "DefParser | None" has no attribute "parse_file" [union-attr] +pint\facets\plain\registry.py:598: error: Argument 1 to "parse_file" of "DefParser" has incompatible type "Iterable[str] | str | Path"; expected "Path | str" [arg-type] +pint\facets\plain\registry.py:600: error: Item "None" of "DefParser | None" has no attribute "iter_parsed_project" [union-attr] +pint\facets\plain\registry.py:644: error: Argument 2 to "setdefault" of "MutableMapping" has incompatible type "set[Never]"; expected "frozenset[str]" [arg-type] +pint\facets\plain\registry.py:646: error: "frozenset[str]" has no attribute "add" [attr-defined] +pint\facets\plain\registry.py:748: error: Argument 1 to "__call__" of "_NumberOp" has incompatible type "Decimal"; expected "int | float | complex | number[Any] | bool" [arg-type] +pint\facets\plain\registry.py:748: error: Argument 1 to "__call__" of "_NumberOp" has incompatible type "Fraction"; expected "int | float | complex | number[Any] | bool" [arg-type] +pint\facets\plain\registry.py:760: error: Incompatible types in assignment (expression has type "float | Any | int | Decimal", target has type "int") [assignment] +pint\facets\plain\registry.py:763: error: Incompatible types in assignment (expression has type "UnitDefinition", variable has type "DimensionDefinition | DerivedDimensionDefinition") [assignment] +pint\facets\plain\registry.py:764: error: Item "DimensionDefinition" of "DimensionDefinition | DerivedDimensionDefinition" has no attribute "reference" [union-attr] +pint\facets\plain\registry.py:765: error: Item "DimensionDefinition" of "DimensionDefinition | DerivedDimensionDefinition" has no attribute "reference" [union-attr] +pint\facets\plain\registry.py:795: error: Argument 1 to "__call__" of "_NumberOp" has incompatible type "Decimal"; expected "int | float | complex | number[Any] | bool" [arg-type] +pint\facets\plain\registry.py:795: error: Argument 1 to "__call__" of "_NumberOp" has incompatible type "Fraction"; expected "int | float | complex | number[Any] | bool" [arg-type] +pint\facets\plain\registry.py:824: error: Argument 2 to "to_units_container" has incompatible type "GenericPlainRegistry[QuantityT, UnitT]"; expected "UnitRegistry | None" [arg-type] +pint\facets\plain\registry.py:858: error: Argument 3 to "DimensionalityError" has incompatible type "UnitsContainer"; expected "str" [arg-type] +pint\facets\plain\registry.py:858: error: Argument 4 to "DimensionalityError" has incompatible type "UnitsContainer"; expected "str" [arg-type] +pint\facets\plain\registry.py:910: error: Item "None" of "Converter | None" has no attribute "is_multiplicative" [union-attr] +pint\facets\plain\registry.py:911: error: Incompatible types in assignment (expression has type "None", variable has type "int") [assignment] +pint\facets\plain\registry.py:958: error: Argument 1 to "__call__" of "_NumberOp" has incompatible type "Decimal"; expected "int | float | complex | number[Any] | bool" [arg-type] +pint\facets\plain\registry.py:958: error: Argument 1 to "__call__" of "_NumberOp" has incompatible type "Fraction"; expected "int | float | complex | number[Any] | bool" [arg-type] +pint\facets\plain\registry.py:962: error: Incompatible types in assignment (expression has type "float | Any | int | Decimal", target has type "int") [assignment] +pint\facets\plain\registry.py:964: error: Item "Converter" of "Converter | None" has no attribute "scale" [union-attr] +pint\facets\plain\registry.py:964: error: Item "None" of "Converter | None" has no attribute "scale" [union-attr] +pint\facets\plain\registry.py:1042: error: Argument 2 to "to_units_container" has incompatible type "GenericPlainRegistry[QuantityT, UnitT]"; expected "UnitRegistry | None" [arg-type] +pint\facets\plain\registry.py:1044: error: Argument 2 to "to_units_container" has incompatible type "GenericPlainRegistry[QuantityT, UnitT]"; expected "UnitRegistry | None" [arg-type] +pint\facets\plain\registry.py:1094: error: Argument 1 to "__call__" of "_NumberOp" has incompatible type "T"; expected "int | float | complex | number[Any] | bool" [arg-type] +pint\facets\plain\registry.py:1094: error: Incompatible types in assignment (expression has type "float | int | Decimal | Any", variable has type "T") [assignment] +pint\facets\plain\registry.py:1096: error: Argument 1 to "__call__" of "_NumberOp" has incompatible type "T"; expected "int | float | complex | number[Any] | bool" [arg-type] +pint\facets\plain\registry.py:1096: error: Incompatible types in assignment (expression has type "float | int | Decimal | Any", variable has type "T") [assignment] +pint\facets\plain\registry.py:1268: error: Argument 2 to "add" of "UnitsContainer" has incompatible type "float | int | Decimal | Fraction | number[Any]"; expected "Number" [arg-type] +pint\facets\plain\registry.py:1359: error: Incompatible types in assignment (expression has type "dict[str, str | Any]", variable has type "Match[str]") [assignment] +pint\facets\plain\registry.py:1364: error: "Match[str]" has no attribute "items" [attr-defined] +pint\facets\plain\registry.py:1374: error: Incompatible return value type (got "list[list[Any]]", expected "list[str] | str | None") [return-value] +pint\facets\plain\registry.py:1407: error: Argument 1 to "_eval_token" of "GenericPlainRegistry" has incompatible type "str"; expected "TokenInfo" [arg-type] +pint\facets\numpy\quantity.py:175: error: Item "float" of the upper bound "float | int | Decimal | Fraction | number[Any] | ndarray[Any, Any]" of type variable "MagnitudeT" has no attribute "shape" [union-attr] +pint\facets\numpy\quantity.py:175: error: Item "int" of the upper bound "float | int | Decimal | Fraction | number[Any] | ndarray[Any, Any]" of type variable "MagnitudeT" has no attribute "shape" [union-attr] +pint\facets\numpy\quantity.py:175: error: Item "Decimal" of the upper bound "float | int | Decimal | Fraction | number[Any] | ndarray[Any, Any]" of type variable "MagnitudeT" has no attribute "shape" [union-attr] +pint\facets\numpy\quantity.py:175: error: Item "Fraction" of the upper bound "float | int | Decimal | Fraction | number[Any] | ndarray[Any, Any]" of type variable "MagnitudeT" has no attribute "shape" [union-attr] +pint\facets\numpy\quantity.py:181: error: Name "shape" already defined on line 173 [no-redef] +pint\facets\numpy\quantity.py:181: error: "Callable[[NumpyQuantity[MagnitudeT]], tuple[int, ...]]" has no attribute "setter" [attr-defined] +pint\facets\numpy\quantity.py:183: error: Item "float" of the upper bound "float | int | Decimal | Fraction | number[Any] | ndarray[Any, Any]" of type variable "MagnitudeT" has no attribute "shape" [union-attr] +pint\facets\numpy\quantity.py:183: error: Item "int" of the upper bound "float | int | Decimal | Fraction | number[Any] | ndarray[Any, Any]" of type variable "MagnitudeT" has no attribute "shape" [union-attr] +pint\facets\numpy\quantity.py:183: error: Item "Decimal" of the upper bound "float | int | Decimal | Fraction | number[Any] | ndarray[Any, Any]" of type variable "MagnitudeT" has no attribute "shape" [union-attr] +pint\facets\numpy\quantity.py:183: error: Item "Fraction" of the upper bound "float | int | Decimal | Fraction | number[Any] | ndarray[Any, Any]" of type variable "MagnitudeT" has no attribute "shape" [union-attr] +pint\facets\numpy\quantity.py:183: error: Property "shape" defined in "generic" is read-only [misc] +pint\facets\numpy\quantity.py:217: error: Argument 1 to "len" has incompatible type "MagnitudeT"; expected "Sized" [arg-type] +pint\facets\numpy\quantity.py:274: error: Unsupported target for indexed assignment ("MagnitudeT") [index] +pint\facets\numpy\quantity.py:296: error: Unsupported target for indexed assignment ("MagnitudeT") [index] +pint\facets\numpy\quantity.py:298: error: Unsupported target for indexed assignment ("MagnitudeT") [index] +pint\facets\nonmultiplicative\definitions.py:30: error: Argument 1 to "__call__" of "_NumberOp" has incompatible type "Number"; expected "int | float | complex | number[Any] | bool" [arg-type] +pint\facets\nonmultiplicative\definitions.py:33: error: Argument 1 to "__call__" of "_NumberOp" has incompatible type "Number"; expected "int | float | complex | number[Any] | bool" [arg-type] +pint\facets\nonmultiplicative\definitions.py:89: error: Argument 1 to "__call__" of "_NumberOp" has incompatible type "Number"; expected "int | float | complex | number[Any] | bool" [arg-type] +pint\facets\nonmultiplicative\definitions.py:91: error: Argument 1 to "__call__" of "_UFunc_Nin1_Nout1" has incompatible type "float | Any | int | Decimal"; expected "int | float | complex | str | bytes | generic" [arg-type] +pint\facets\nonmultiplicative\definitions.py:91: error: Argument 2 to "__call__" of "_UFunc_Nin1_Nout1" has incompatible type "float | Any | int | Decimal"; expected "None" [arg-type] +pint\facets\nonmultiplicative\definitions.py:93: error: Argument 1 to "__call__" of "_UFunc_Nin1_Nout1" has incompatible type "float | Any | int | Decimal"; expected "int | float | complex | str | bytes | generic" [arg-type] +pint\facets\nonmultiplicative\definitions.py:96: error: Argument 1 to "__call__" of "_UFunc_Nin1_Nout1" has incompatible type "float | Decimal | Any"; expected "int | float | complex | str | bytes | generic" [arg-type] +pint\facets\nonmultiplicative\definitions.py:96: error: Argument 1 to "__call__" of "_NumberOp" has incompatible type "Number"; expected "int | float | complex | number[Any] | bool" [arg-type] +pint\facets\nonmultiplicative\definitions.py:110: error: Argument 1 to "__call__" of "_UFunc_Nin1_Nout1" has incompatible type "float | int | Decimal | Fraction | number[Any] | ndarray[Any, Any]"; expected "Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes]" [arg-type] +pint\facets\nonmultiplicative\definitions.py:110: error: Argument 2 to "__call__" of "_UFunc_Nin1_Nout1" has incompatible type "float | int | Decimal | Fraction | number[Any] | ndarray[Any, Any]"; expected "ndarray[Any, dtype[Any]] | tuple[ndarray[Any, dtype[Any]]] | None" [arg-type] +pint\facets\nonmultiplicative\definitions.py:112: error: Argument 1 to "__call__" of "_UFunc_Nin1_Nout1" has incompatible type "float | int | Decimal | Fraction | number[Any] | ndarray[Any, Any]"; expected "int | float | complex | str | bytes | generic" [arg-type] +pint\facets\nonmultiplicative\definitions.py:113: error: Argument 1 to "__call__" of "_NumberOp" has incompatible type "Number"; expected "int | float | complex | number[Any] | bool" [arg-type] +pint\facets\group\definitions.py:31: error: Missing return statement [return] +pint\facets\nonmultiplicative\registry.py:208: error: Argument 2 to "add" of "UnitsContainer" has incompatible type "float | int | Decimal | Fraction | number[Any]"; expected "Number" [arg-type] +pint\facets\nonmultiplicative\registry.py:212: error: Incompatible return value type (got "UnitsContainer | None", expected "UnitsContainer") [return-value] +pint\facets\nonmultiplicative\registry.py:269: error: Argument 3 to "DimensionalityError" has incompatible type "UnitsContainer"; expected "str" [arg-type] +pint\facets\nonmultiplicative\registry.py:269: error: Argument 4 to "DimensionalityError" has incompatible type "UnitsContainer"; expected "str" [arg-type] +pint\facets\nonmultiplicative\registry.py:275: error: Item "None" of "Converter | None" has no attribute "to_reference" [union-attr] +pint\facets\nonmultiplicative\registry.py:275: error: Incompatible types in assignment (expression has type "float | int | Decimal | Fraction | number[Any] | ndarray[Any, Any] | Any", variable has type "T") [assignment] +pint\facets\nonmultiplicative\registry.py:275: error: Argument 1 to "to_reference" of "Converter" has incompatible type "T"; expected "float | int | Decimal | Fraction | number[Any] | ndarray[Any, Any]" [arg-type] +pint\facets\nonmultiplicative\registry.py:293: error: Item "None" of "Converter | None" has no attribute "from_reference" [union-attr] +pint\facets\nonmultiplicative\registry.py:293: error: Incompatible types in assignment (expression has type "float | int | Decimal | Fraction | number[Any] | ndarray[Any, Any] | Any", variable has type "T") [assignment] +pint\facets\nonmultiplicative\registry.py:294: error: Argument 1 to "from_reference" of "Converter" has incompatible type "T"; expected "float | int | Decimal | Fraction | number[Any] | ndarray[Any, Any]" [arg-type] +pint\facets\measurement\registry.py:30: error: Value of type variable "TT" of "create_class_with_registry" cannot be "Measurement" [type-var] +pint\facets\measurement\registry.py:30: error: Argument 1 to "create_class_with_registry" has incompatible type "GenericMeasurementRegistry[QuantityT, UnitT]"; expected "UnitRegistry" [arg-type] +pint\facets\measurement\registry.py:38: error: Incompatible types in assignment (expression has type "Callable[[VarArg(Any), KwArg(Any)], Any]", variable has type "type[Measurement]") [assignment] +pint\facets\context\objects.py:222: error: Incompatible return value type (got "PlainQuantity[Any]", expected "float | int | Decimal | Fraction | number[Any] | ndarray[Any, Any]") [return-value] +pint\facets\context\objects.py:222: error: Argument 2 to "__call__" of "Transformation" has incompatible type "float | int | Decimal | Fraction | number[Any] | ndarray[Any, Any]"; expected "PlainQuantity[Any]" [arg-type] +pint\facets\context\objects.py:236: error: Argument 1 to "ParserConfig" has incompatible type "type[float]"; expected "type[Number]" [arg-type] +pint\facets\context\objects.py:239: error: Incompatible types in assignment (expression has type "ParsedStatement[ParserConfig]", variable has type "str") [assignment] +pint\facets\group\registry.py:56: error: Value of type variable "TT" of "create_class_with_registry" cannot be "Group" [type-var] +pint\facets\group\registry.py:56: error: Incompatible types in assignment (expression has type "type[Group]", variable has type "") [assignment] +pint\facets\group\registry.py:56: error: Argument 1 to "create_class_with_registry" has incompatible type "GenericGroupRegistry[QuantityT, UnitT]"; expected "UnitRegistry" [arg-type] +pint\facets\group\registry.py:95: error: "" has no attribute "from_definition" [attr-defined] +pint\facets\context\registry.py:36: error: Need type annotation for "root_units" (hint: "root_units: dict[, ] = ...") [var-annotated] +pint\facets\context\registry.py:39: error: Need type annotation for "conversion_factor" (hint: "conversion_factor: dict[, ] = ...") [var-annotated] +pint\facets\context\registry.py:66: error: Need type annotation for "_caches" (hint: "_caches: dict[, ] = ...") [var-annotated] +pint\facets\context\registry.py:68: error: Need type annotation for "_context_units" (hint: "_context_units: dict[, ] = ...") [var-annotated] +pint\facets\context\registry.py:73: error: Incompatible types in assignment (expression has type "ChainMap[str, UnitDefinition]", base class "GenericPlainRegistry" defined the type as "dict[str, UnitDefinition]") [assignment] +pint\facets\context\registry.py:113: error: Argument 1 to "__delitem__" of "dict" has incompatible type "str | None"; expected "str" [arg-type] +pint\facets\context\registry.py:146: error: Incompatible types in assignment (expression has type "ContextCacheOverlay", variable has type "RegistryCache") [assignment] +pint\facets\context\registry.py:148: error: Incompatible types in assignment (expression has type "dict[Never, Never]", variable has type "bool") [assignment] +pint\facets\context\registry.py:149: error: Argument 2 to "insert" of "list" has incompatible type "Literal[True]"; expected "MutableMapping[str, UnitDefinition]" [arg-type] +pint\facets\context\registry.py:199: error: Argument 1 to "define" of "GenericPlainRegistry" has incompatible type "UnitDefinition"; expected "str | type" [arg-type] +pint\facets\context\registry.py:399: error: Incompatible types in assignment (expression has type "QuantityT", variable has type "UnitsContainer") [assignment] +pint\facets\context\registry.py:401: error: Argument 4 to "transform" of "ContextChain" has incompatible type "UnitsContainer"; expected "float | int | Decimal | Fraction | number[Any] | ndarray[Any, Any]" [arg-type] +pint\facets\context\registry.py:403: error: "UnitsContainer" has no attribute "_magnitude" [attr-defined] +pint\facets\context\registry.py:403: error: "UnitsContainer" has no attribute "_units" [attr-defined] +pint\facets\system\objects.py:90: note: By default the bodies of untyped functions are not checked, consider using --check-untyped-defs [annotation-unchecked] +pint\facets\system\objects.py:127: error: "str" has no attribute "measurement_systems" [attr-defined] +pint\facets\system\objects.py:156: error: Incompatible types in assignment (expression has type "Callable[[str | dict[str, float | int | Decimal | Fraction | number[Any]] | UnitsContainer | PlainUnit, bool], tuple[float | int | Decimal | Fraction | number[Any], Unit]]", variable has type "Callable[[str | dict[str, float | int | Decimal | Fraction | number[Any]] | UnitsContainer | PlainUnit, bool], tuple[Number, str | dict[str, float | int | Decimal | Fraction | number[Any]] | UnitsContainer | PlainUnit]] | None") [assignment] +pint\facets\system\objects.py:158: error: Need type annotation for "derived_unit_names" (hint: "derived_unit_names: list[] = ...") [var-annotated] +pint\facets\system\objects.py:161: error: Too few arguments [call-arg] +pint\facets\system\objects.py:161: error: "None" not callable [misc] +pint\facets\system\objects.py:173: error: Too few arguments [call-arg] +pint\facets\system\objects.py:173: error: "None" not callable [misc] +pint\facets\system\objects.py:181: error: Too few arguments [call-arg] +pint\facets\system\objects.py:181: error: "None" not callable [misc] +pint\facets\system\objects.py:201: error: Argument 1 to "update" of "MutableMapping" has incompatible type "**dict[str, dict[str, float | Decimal | Any]]"; expected "dict[str, Number]" [arg-type] +pint\facets\system\registry.py:68: error: Value of type variable "TT" of "create_class_with_registry" cannot be "System" [type-var] +pint\facets\system\registry.py:68: error: Argument 1 to "create_class_with_registry" has incompatible type "GenericSystemRegistry[QuantityT, UnitT]"; expected "UnitRegistry" [arg-type] +pint\facets\system\registry.py:97: error: Missing positional arguments "definition_type", "msg" in call to "DefinitionError" [call-arg] +pint\facets\system\registry.py:204: error: Incompatible types in assignment (expression has type "UnitsContainer", variable has type "UnitT") [assignment] +pint\facets\system\registry.py:204: error: Argument 2 to "to_units_container" has incompatible type "GenericSystemRegistry[QuantityT, UnitT]"; expected "UnitRegistry | None" [arg-type] +pint\facets\system\registry.py:208: error: Argument 1 to "get_system" of "GenericSystemRegistry" has incompatible type "str | System"; expected "str" [arg-type] +pint\facets\system\registry.py:210: error: "UnitT" has no attribute "items" [attr-defined] +pint\facets\system\registry.py:213: error: Incompatible types in assignment (expression has type "UnitsContainer", variable has type "dict[str, Number]") [assignment] +pint\facets\system\registry.py:213: error: Argument 1 to "to_units_container" has incompatible type "dict[str, Number]"; expected "PlainQuantity[Any] | str | dict[str, float | int | Decimal | Fraction | number[Any]] | UnitsContainer | PlainUnit | None" [arg-type] +pint\facets\system\registry.py:213: error: Argument 2 to "to_units_container" has incompatible type "GenericSystemRegistry[QuantityT, UnitT]"; expected "UnitRegistry | None" [arg-type] +pint\facets\system\registry.py:221: error: Incompatible types in assignment (expression has type "tuple[float | int | Decimal | Fraction | number[Any], UnitsContainer]", target has type "UnitsContainer") [assignment] +pint\facets\system\registry.py:233: error: Argument 1 to "get_compatible_units" of "GenericGroupRegistry" has incompatible type "PlainQuantity[Any] | str | dict[str, float | int | Decimal | Fraction | number[Any]] | UnitsContainer | PlainUnit"; expected "UnitsContainer" [arg-type] +Found 141 errors in 14 files (checked 33 source files) diff --git a/pint/_typing.py b/pint/_typing.py index 241459ef1..44f488bd5 100644 --- a/pint/_typing.py +++ b/pint/_typing.py @@ -48,5 +48,10 @@ class Handler(Protocol): + @overload + def __getitem__(self, Never, /) -> Never: + ... + + @overload def __getitem__(self, item: type[T]) -> Callable[[T], None]: ... diff --git a/pint/delegates/txt_defparser/defparser.py b/pint/delegates/txt_defparser/defparser.py index 75a8ee75c..1e052fd4b 100644 --- a/pint/delegates/txt_defparser/defparser.py +++ b/pint/delegates/txt_defparser/defparser.py @@ -68,7 +68,9 @@ class DefParser: plain.CommentDefinition, ) - def __init__(self, default_config: ParserConfig, diskcache: fc.DiskCache) -> None: + def __init__( + self, default_config: ParserConfig, diskcache: fc.DiskCache | None + ) -> None: self._default_config = default_config self._diskcache = diskcache diff --git a/pint/facets/nonmultiplicative/registry.py b/pint/facets/nonmultiplicative/registry.py index 7f58d060c..2af973177 100644 --- a/pint/facets/nonmultiplicative/registry.py +++ b/pint/facets/nonmultiplicative/registry.py @@ -94,6 +94,7 @@ def _add_unit(self, definition: UnitDefinition) -> None: "delta_" + alias for alias in definition.aliases ) + assert isinstance(definition.reference, UnitsContainer) delta_reference = self.UnitsContainer( {ref: value for ref, value in definition.reference.items()} ) @@ -198,6 +199,7 @@ def _add_ref_of_log_or_offset_unit( # TODO: Check that reference is None + assert isinstance(slct_ref, UnitsContainer) # If reference unit is not dimensionless if slct_ref != UnitsContainer(): # Extract reference unit diff --git a/pint/facets/plain/definitions.py b/pint/facets/plain/definitions.py index edf122149..4e9f3d4e0 100644 --- a/pint/facets/plain/definitions.py +++ b/pint/facets/plain/definitions.py @@ -13,7 +13,7 @@ import typing as ty from dataclasses import dataclass from functools import cached_property -from typing import Any +from typing import Any, no_type_check from ... import errors from ..._typing import Magnitude @@ -121,7 +121,7 @@ class UnitDefinition(NamedDefinition, errors.WithDefErr): defined_symbol: str | None #: additional names for the same unit aliases: tuple[str, ...] - #: A functiont that converts a value in these units into the reference units + #: A function that converts a value in these units into the reference units # TODO: this has changed as converter is now annotated as converter. # Briefly, in several places converter attributes like as_multiplicative were # accesed. So having a generic function is a no go. @@ -192,7 +192,7 @@ def is_base(self) -> bool: """Indicates if it is a base unit.""" # TODO: This is set in __post_init__ - return self._is_base + return self._is_base # type: ignore[attr-defined] @property def is_multiplicative(self) -> bool: @@ -283,8 +283,10 @@ def __post_init__(self): class ScaleConverter(Converter): """A linear transformation without offset.""" - scale: float + scale: numbers.Number + # typing non_int_type related + @no_type_check def to_reference(self, value: Magnitude, inplace: bool = False) -> Magnitude: if inplace: value *= self.scale @@ -293,6 +295,8 @@ def to_reference(self, value: Magnitude, inplace: bool = False) -> Magnitude: return value + # typing non_int_type related + @no_type_check def from_reference(self, value: Magnitude, inplace: bool = False) -> Magnitude: if inplace: value /= self.scale diff --git a/pint/facets/plain/qto.py b/pint/facets/plain/qto.py index 64d368406..b2555d5ec 100644 --- a/pint/facets/plain/qto.py +++ b/pint/facets/plain/qto.py @@ -4,7 +4,7 @@ import math import numbers import warnings -from typing import TYPE_CHECKING +from typing import TYPE_CHECKING, no_type_check from ...compat import ( mip_INF, @@ -193,7 +193,7 @@ def to_preferred( def ito_preferred( quantity: PlainQuantity, preferred_units: list[UnitLike] | None = None -) -> PlainQuantity: +) -> None: """Return Quantity converted to a unit composed of the preferred units. Examples @@ -211,9 +211,10 @@ def ito_preferred( return quantity.ito(units) +@no_type_check def _get_preferred( quantity: PlainQuantity, preferred_units: list[UnitLike] | None = None -) -> PlainQuantity: +) -> UnitsContainer: if preferred_units is None: preferred_units = quantity._REGISTRY.default_preferred_units diff --git a/pint/facets/plain/registry.py b/pint/facets/plain/registry.py index f1fa16387..7c49bdfb7 100644 --- a/pint/facets/plain/registry.py +++ b/pint/facets/plain/registry.py @@ -647,7 +647,6 @@ def _build_cache(self, loaded_files=None) -> None: except Exception as exc: logger.warning(f"Could not resolve {unit_name}: {exc!r}") - return self._cache def get_name(self, name_or_alias: str, case_sensitive: bool | None = None) -> str: """Return the canonical name of a unit.""" diff --git a/pint/facets/system/definitions.py b/pint/facets/system/definitions.py index f47a23fd8..8b52b78c2 100644 --- a/pint/facets/system/definitions.py +++ b/pint/facets/system/definitions.py @@ -57,6 +57,7 @@ def from_lines( for definition in parser.iter_parsed_project(pp): if isinstance(definition, cls): return definition + return None @property def unit_replacements(self) -> tuple[tuple[str, str | None], ...]: diff --git a/pint/facets/system/registry.py b/pint/facets/system/registry.py index c614348e5..ae3d04644 100644 --- a/pint/facets/system/registry.py +++ b/pint/facets/system/registry.py @@ -18,7 +18,7 @@ if TYPE_CHECKING: from ..._typing import Quantity, Unit -from ..._typing import UnitLike +from ..._typing import QuantityOrUnitLike, UnitLike from ...util import UnitsContainer as UnitsContainerT from ...util import ( create_class_with_registry, @@ -223,7 +223,7 @@ def _get_base_units( return base_factor, destination_units def get_compatible_units( - self, input_units: UnitsContainerT, group_or_system: str | None = None + self, input_units: QuantityOrUnitLike, group_or_system: str | None = None ) -> frozenset[Unit]: """ """ @@ -240,7 +240,7 @@ def get_compatible_units( def _get_compatible_units( self, input_units: UnitsContainerT, group_or_system: str | None = None - ) -> frozenset[Unit]: + ) -> frozenset[str]: if group_or_system and group_or_system in self._systems: members = self._systems[group_or_system].members # group_or_system has been handled by System diff --git a/pyproject.toml b/pyproject.toml index dea45d96f..f107d2cb9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -119,3 +119,4 @@ exclude = [ "pint/default_en.txt", "pint/constants_en.txt", ] +disable_error_code = "operator,override"