-
Notifications
You must be signed in to change notification settings - Fork 441
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Python 3 style using pyupgrade #3638
Conversation
Codecov Report
@@ Coverage Diff @@
## main #3638 +/- ##
=======================================
Coverage 95.11% 95.12%
=======================================
Files 83 83
Lines 18560 18556 -4
=======================================
- Hits 17654 17652 -2
+ Misses 906 904 -2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch on most of these, thanks. I only have a few remarks.
I've added a pre-commit for
git diffdiff --git a/pyvista/plotting/colors.py b/pyvista/plotting/colors.py
index 6903e34f..86f4713e 100644
--- a/pyvista/plotting/colors.py
+++ b/pyvista/plotting/colors.py
@@ -460,10 +460,10 @@ class Color:
def __init__(
self,
- color: Optional[color_like] = None,
- opacity: Optional[Union[int, float, str]] = None,
- default_color: Optional[color_like] = None,
- default_opacity: Union[int, float, str] = 255,
+ color: color_like | None = None,
+ opacity: int | float | str | None = None,
+ default_color: color_like | None = None,
+ default_opacity: int | float | str = 255,
):
"""Initialize new instance."""
self._red, self._green, self._blue, self._opacity = 0, 0, 0, 0
@@ -543,7 +543,7 @@ class Color:
return h
@staticmethod
- def convert_color_channel(val: Union[int, np.integer, float, np.floating, str]) -> int:
+ def convert_color_channel(val: int | np.integer | float | np.floating | str) -> int:
"""Convert the given color channel value to the integer representation.
Parameters
@@ -629,7 +629,7 @@ class Color:
raise ValueError(f"Invalid color name or hex string: {arg}") from None
@property
- def int_rgba(self) -> Tuple[int, int, int, int]:
+ def int_rgba(self) -> tuple[int, int, int, int]:
"""Get the color value as an RGBA integer tuple.
Examples
@@ -655,7 +655,7 @@ class Color:
return self._red, self._green, self._blue, self._opacity
@property
- def int_rgb(self) -> Tuple[int, int, int]:
+ def int_rgb(self) -> tuple[int, int, int]:
"""Get the color value as an RGB integer tuple.
Examples
@@ -681,7 +681,7 @@ class Color:
return self.int_rgba[:3]
@property
- def float_rgba(self) -> Tuple[float, float, float, float]:
+ def float_rgba(self) -> tuple[float, float, float, float]:
"""Get the color value as an RGBA float tuple.
Examples
@@ -707,7 +707,7 @@ class Color:
return self._red / 255.0, self._green / 255.0, self._blue / 255.0, self._opacity / 255.0
@property
- def float_rgb(self) -> Tuple[float, float, float]:
+ def float_rgb(self) -> tuple[float, float, float]:
"""Get the color value as an RGB float tuple.
Examples
@@ -787,7 +787,7 @@ class Color:
return self.hex_rgba[:-2]
@property
- def name(self) -> Optional[str]:
+ def name(self) -> str | None:
"""Get the color name.
Returns |
@mwtoews I'm not quite sure how I feel about that diff about runtime typing. If I understand correctly, In other words, what are the exact risks associated with |
@adeak the way I understand it is that |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work, thanks a lot @mwtoews!
* upstream/main: Python 3 style using pyupgrade (pyvista#3638) Move google_analytics_id to analytics in pydata-sphinx-theme (pyvista#3634)
Overview
This upgrades a few Python 3 styles, automated using pyupgrade, using the command:
$ pyupgrade --py37-plus `find . -name "*.py*"`
with a few manual edits for quality control.
Details
r'doctest: *\+SKIP')
; I believe "noqa: W605" was incorrect and should not have been ignoredset
comprehension and literalsIf any of these styles are objectionable and the current is preferred, note these and I'll restore them.