summaryrefslogtreecommitdiff
path: root/pint/delegates
Commit message (Collapse)AuthorAgeFilesLines
* Python's 3.9 compatible typing annotationsHernan Grecco2023-05-142-5/+9
|
* Typing related fixesHernan Grecco2023-05-095-10/+10
|
* Large commit to make Pint more typing friendlyHernan Grecco2023-05-051-1/+1
| | | | | | | | | | | | | | | | | | | | | 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.
* Typing improvementsHernan Grecco2023-05-0111-78/+171
| | | | | | | | | | | 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.
* Run refurb --python-version 3.9 in codeHernan Grecco2023-04-291-8/+5
|
* Run pyupgrade --py39-plus in all files except _vendorHernan Grecco2023-04-293-7/+6
|
* Run pre-commit run --all-files . Mostly removed empty linesHernan2023-04-243-5/+0
|
* Rename parser to defparserHernan2022-10-1211-28/+28
|
* Final step to split the registry from the parserHernan2022-09-3011-0/+1130
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.