summaryrefslogtreecommitdiff
path: root/pint/util.py
Commit message (Collapse)AuthorAgeFilesLines
* Python's 3.9 compatible typing annotationsHernan Grecco2023-05-141-10/+11
|
* SharedObject module should beHernan Grecco2023-05-111-1/+1
|
* Better SharedRegistryObjects creationHernan Grecco2023-05-111-1/+11
|
* Remove unnecessary import in utilHernan Grecco2023-05-111-2/+2
|
* Large commit to make Pint more typing friendlyHernan Grecco2023-05-051-21/+34
| | | | | | | | | | | | | | | | | | | | | In this very large commit we tackle a few aspects of Pint that makes it difficult to do static typing. 1. Dynamic classes became static: Quantity and Unit are now (for the most part) static classes with a static inheritance. This allows mypy/pylance and other type checker to properly inspect them. 2. Added types through out all the code. (WIP) 3. Refactor minor parts of the code to make it more typing homogeneous. Catch a few potential bugs in the way. 4. Add several TODOs that need to be addressed in 0.23 5. Moved some group and system and context code out of the PlainRegistry 6. Moved certain specialized methods out of the PlainRegistry.
* Fix 3.9 support. TypeAlias is supported in 3.10+Hernan Grecco2023-05-011-3/+6
|
* Run pyupgrade --py39-plusHernan Grecco2023-05-011-2/+1
|
* Typing improvementsHernan Grecco2023-05-011-195/+309
| | | | | | | | | | | While there is still a lot of work to do (mainly in Registry, Quantity, Unit), this large PR makes several changes all around the code. There has not been any intended functional change, but certain typing improvements required code minor code refactoring to streamline input and output types of functions. An important experimental idea is the PintScalar and PintArray protocols, and Magnitude type. This is to overcome the lack of a proper numerical hierarchy in Python.
* Reworked the Quantity, Unit, Measurement, Group and System class to be ↵Hernan Grecco2023-04-301-28/+0
| | | | static to ease with typing
* Run pyupgrade --py39-plus in all files except _vendor (again)Hernan Grecco2023-04-291-1/+1
|
* Run refurb --python-version 3.9 in codeHernan Grecco2023-04-291-8/+6
|
* Run pyupgrade --py39-plus in all files except _vendorHernan Grecco2023-04-291-24/+24
|
* Remove deprecated use_decimalHernan Grecco2023-04-291-9/+1
|
* Apply NEP-29: Pint now requires Python 3.9+ and NumPy 1.21+Hernan Grecco2023-04-291-3/+1
|
* Merge branch 'master' into patch-type-importsHernan Grecco2023-04-241-4/+3
|\
| * Run pre-commit run --all-files . Mostly removed empty linesHernan2023-04-241-1/+0
| |
| * Merge branch 'master' into degree-parsingHernan Grecco2023-04-241-2/+2
| |\
| | * Merge branch 'master' into fix-trailing-zeros-decimalHernan Grecco2023-04-241-1/+1
| | |\
| | | * modify string pre-processing such that multiplication operator is inserted ↵Benjamin W. Portner2023-01-191-1/+1
| | | | | | | | | | | | | | | | before and after brackets, e.g. 2 (3 + 4) -> 2 * (3 + 4)
| | | * - fix error in string pre-processingBenjamin W. Portner2023-01-181-1/+1
| | | | | | | | | | | | | | | | - add tests for pre-processed tree evaluation
| | * | Merge branch 'master' into fix-trailing-zeros-decimalToon Verstraelen2022-10-301-3/+12
| | |\ \ | | | |/
| | * | Fix creation of trailing zeros in Decimal objects when converting unitsToon Verstraelen2022-10-231-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Fixes #1621 I've also modified conftest, to facilitate testing with customized unit registries. This is to be discussed, obviously.
| * | | Parse '°' along with previous text, not adding a preceding spaceConstantine Evans2023-03-201-1/+1
| | |/ | |/| | | | | | | | | | | | | | | | | | | Currently, as tokenize.tokenizer does not parse ° as a NAME, it is translated to " degree". However, the preceding space means that units with a ° in the middle, for example, Δ°C, cannot be parsed. Removing the preceding space fixes this, and does not appear to break any tests.
* | | appease lintersAustin Orr2022-12-201-2/+1
| | |
* | | patch imports during type checkAustin Orr2022-12-201-2/+2
|/ /
* | Simplify registry subclassingHernan2022-10-251-3/+12
|/
* Merge pull request #1595 from hgrecco/using_flexparserHernan Grecco2022-10-211-74/+0
|\ | | | | Final step to split the registry from the parser
| * Final step to split the registry from the parserHernan2022-09-301-74/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Overview: - All the code in facets is now independent of the definition textual format. In particular, defintions such as UnitDefinition, ContextDefinition an so on cannot be built directly from a string. (some functions are kept only temporarily to simplify but transition) Building Definition objects from string requires a parser that emits them. - The standart pint format is implemented in delegates/txt_parser using flexparser. Briefly each single line statement is mapped to a ParsedStatement class and each larger construct to a Block class. - The registry then has an adder function that takes a definition an incorporate it into the registry. A few nice features of this approach: 1. The Definition objects are standalone public objects, you can now build them in a programatic way and incorporate them to the registry using the define function that will dispatch to the correct adder: >>> new_unit = UnitDefintion( ....) >>> ureg.define(new_unit) # might be called add in the future No more being forced to use string definitions (but you can still use them if you want) 2. Composition over inheritance. The Registry does not know how to parse a definition, but it delegates this to another class which can be changed. This makes it very easy to write another parser (faster, simpler) o try out a completely different file format. 3. Error messages can be more meaningful. Backwards incompatible changes - is_base parameter Definitions is not needed any more. It is now computed automatically leading to a leaner experience and also avoiding incompatible states - alias for dimensionality has been removed (for now at least) The only one defined was speed as an alias of velocity. - (Context|Group|System).from_lines and Definition.from string have been rewritten in terms of the new parser. But will be likely removed in the future - Changing non_int_type is not possible after registry has been created - load_definition raises FileNotFoundError instead of a generic exception if the file was not found - the string representation of several definitions is now not so user friendly terms of the new parser. But will be likely removed in the future - Changing non_int_type is not possible after registry has been created - load_definition raises FileNotFoundError instead of a generic exception if the file was not found - the string representation of several definitions is now not so user friendly.
* | String NaN creation with correct non_int_typeConstantine Evans2022-10-091-1/+1
|/ | | | | | | Creating NaN-value quantities should take into account the non_int_type, and create a magnitude of the correct type. Not all common non_int_type choices support NaN (eg, Fraction does not); this will likely result in a ValueError in that case.
* Modify ParserHelper constructors to facilitate subclassingHernan2022-05-251-2/+2
|
* Change build_dependent_class to only include bases defined in the actual ↵Hernan2022-05-191-4/+6
| | | | | | | registry Prior to this commit, the facet registries could not be built correctly as the dependent classes mro will not be properly ordered.
* Typing and documentation changesHernan2022-05-071-6/+5
|
* Split creation of specialized Quantity, Unit, Measurement classes in twoHernan2022-05-071-6/+11
| | | | | | First we create the class when the registry class is subclassed then we add a reference to the registry when the registry class is instantiated.
* Create Measurement FacetHernan2022-05-071-1/+23
|
* Moved Unit and Quantity to plain facetHernan2022-05-071-8/+9
| | | | | | Note: the word 'plain' was chosen instead of 'base' as BaseUnit or BaseQuantity as the latter might be interpreted physically and not a part of the class hierarchy as intented.
* Create Base FacetHernan2022-05-071-2/+1
| | | | Still need to migrate basic implementation for Quantities and Units
* Run new stable black versionJules Chéron2022-03-301-2/+2
|
* Merge branch 'master' into better_definitionsHernan Grecco2022-03-011-6/+27
|\
| * Improve infer_base_unit type compat and testingConstantine Evans2022-02-091-8/+18
| | | | | | | | | | | | | | infer_base_unit accepted a UnitLike, but could not actually accept a string or UnitsContainer. This uses to_units_container, and the registry paramater, to try to accept all inputs, and throws a ValueError if it can't.
| * Fix to_compact, infer_base_unit for non-float non_int_type (#1461)Constantine Evans2022-02-091-7/+18
| | | | | | | | | | | | | | | | | | | | | | | | | | to_compact used math.log10, which converted non-float types to floats; this caused exceptions when using a non-integer type, like Decimal, that does not implement multiplication/division with floats, and generally changed non-integer types to floats. This addresses the problem by checking non_int_type. If non_int_type != float, it assumes that the type implements a log10 method, as Decimal does. infer_base_unit created a generic UnitsContainer, not a UnitsContainer specific to a registry; this allows specification of a registry, or uses the registry of the passed-in Quantity/UnitLike.
* | Remove UnitsContainer hash from pickle stateHernan2022-02-121-2/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Starting from Python 3.3, the hash value of an object has a random salt that is chosen at interpreter startup. Therefore, pickling and recovering and object hash is incorrect if the the dumpeed value will be used at a different interpreter run. Until this commit, a UnitsContainer that was pickled and then unpickled in a different interpreter would be wrongly consider as unequal. BREAKING CHANGE: This commit will break existing code that relies on keeping the hash across interpreters run. This should be very rare as will require to set the PYTHONHASHSEED value.
* | SourceIterator now contains optioanl filename and is resource flagHernan2022-02-091-1/+3
|/
* Merge pull request #1371 from keewis/custom-formatsJules Chéron2021-10-091-2/+2
|\ | | | | custom unit formats
| * explicitly pass the registry to `format_unit`Keewis2021-08-181-2/+2
| |
* | Merge branch 'master' into application_registryKeewis2021-08-201-4/+2
|\ \ | |/
| * Fix #1360 parsing units with same exponents but different signJules Chéron2021-08-051-4/+2
| |
* | remove _APP_DIRKeewis2021-08-081-2/+2
| |
* | save the actual registry in shared registry objectsKeewis2021-08-061-1/+1
|/
* Add pint typing moduleJules Chéron2021-08-011-15/+33
| | | | | | | | | | | | | | - Quantity as Generic class - Add overloaded signature for __new__ Quantity - Add typing module as private - Add py.typed for PEP561 supports - Add overloaded signature for __new__ Quantity - Quantity as Generic class - Add type hints throughout the project - Add py.typed in package data in setup.cfg - Add type hints for decorators - Add type hints for public API of registry.py - Add type hints for units.py
* Fix error on UnitsContainer equality checkRyan Rowe2020-09-251-1/+5
|