Skip to content

Commit

Permalink
Release/2.3.1 (#91)
Browse files Browse the repository at this point in the history
* Added history.

* Added ignore for inheriting final dtype.

* Allow for extra quotes to enable silencing PyCharm complaints.

* Set release date.

Co-authored-by: Ramon <p8u7wAPC5Pg9HYkkCkzA>
  • Loading branch information
ramonhagenaars committed Aug 30, 2022
1 parent 389c5a1 commit aeea6cb
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 6 deletions.
5 changes: 5 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# History

## 2.3.1 (2022-08-30)

- Fixed mypy error of inheriting final dtype as of numpy==1.23.1.
- Allowed for quotes in shape expressions to appease PyCharm.

## 2.3.0 (2022-08-28)

- Added support for subarrays with shape expressions inside structure expressions.
Expand Down
7 changes: 6 additions & 1 deletion USERDOCS.md
Original file line number Diff line number Diff line change
Expand Up @@ -559,8 +559,13 @@ quite far. `MyPy` will support it (to some extent), but you won't have any insta

## FAQ

* PyCharm complains about `Shape[<expression>]`, what should I do? <br/>
*Unfortunately, some IDEs try to parse what's between quotes in a type hint. You are left with 2 options:*
1. *Do nothing, accept the IDE complaints, wait and hope for the IDE to mature*
2. *Use an extra pair of quotes: `Shape['"<expression>"']`*, this appeases PyCharm and is accepted by `nptyping`
* Can `MyPy` do the instance checking? <br/>
*Unfortunately no. The checking done by MyPy is limited to "`ndarray` or not an `ndarray`".*
*Because of the dynamic nature of `numpy`, this is not possible. The checking done by MyPy is limited to "`ndarray` or*
*not an `ndarray`".*
* Will there ever be support for Pandas DataFrames? Or for Tensorflow Tensors? Or for... ? <br/>
*Maybe. Possibly. If there is enough demand for it and if I find the spare time.*

Expand Down
2 changes: 1 addition & 1 deletion constraints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ mypy-extensions==0.4.3
# mypy
nodeenv==1.6.0
# via pyright
numpy==1.22.4 ; python_version >= "3.8"
numpy==1.23.1 ; python_version >= "3.8"
# via -r ./dependencies\requirements.txt
pathspec==0.9.0
# via black
Expand Down
2 changes: 1 addition & 1 deletion nptyping/package_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
SOFTWARE.
"""
__title__ = "nptyping"
__version__ = "2.3.0"
__version__ = "2.3.1"
__author__ = "Ramon Hagenaars"
__author_email__ = "[email protected]"
__description__ = "Type hints for NumPy."
Expand Down
5 changes: 3 additions & 2 deletions nptyping/shape_expression.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ def validate_shape_expression(shape_expression: Union[ShapeExpression, Any]) ->
:param shape_expression: the shape expression to validate.
:return: None.
"""

shape_expression_no_quotes = shape_expression.replace("'", "").replace('"', "")
if shape_expression is not Any and not re.match(
_REGEX_SHAPE_EXPRESSION, shape_expression
_REGEX_SHAPE_EXPRESSION, shape_expression_no_quotes
):
raise InvalidShapeError(
f"'{shape_expression}' is not a valid shape expression."
Expand All @@ -74,6 +74,7 @@ def normalize_shape_expression(shape_expression: ShapeExpression) -> ShapeExpres
:param shape_expression: the shape expression that is to be normalized.
:return: a normalized shape expression.
"""
shape_expression = shape_expression.replace("'", "").replace('"', "")
# Replace whitespaces right before labels with $.
shape_expression = re.sub(rf"\s*{_REGEX_LABEL}", r"$\1", shape_expression)
# Let all commas be followed by a $.
Expand Down
2 changes: 1 addition & 1 deletion nptyping/structure.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@ import numpy as np
Structure = cast(Literal, Structure) # type: ignore[has-type,misc]

# For PyRight:
class Structure(np.dtype[Any]): # type: ignore[no-redef]
class Structure(np.dtype[Any]): # type: ignore[no-redef,misc]
def __class_getitem__(cls, item: Any) -> Any: ...
4 changes: 4 additions & 0 deletions tests/test_shape.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,7 @@ def test_repr(self):
def test_shape_can_be_compared_to_literal(self):
self.assertEqual(Shape["2, 2"], Literal["2, 2"])
self.assertEqual(Shape[" 2 , 2 "], Literal["2,2"])

def test_quotes_are_allowed(self):
self.assertEqual(Shape["2, 2"], Shape["'2, 2'"])
self.assertEqual(Shape["2, 2"], Shape['"2, 2"'])

0 comments on commit aeea6cb

Please sign in to comment.