Skip to content

Commit

Permalink
use ruff instead of pyupgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
joamatab committed Aug 3, 2023
1 parent 086d52c commit 9d20ae7
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 22 deletions.
6 changes: 0 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,6 @@ repos:
hooks:
- id: black

- repo: https://github.com/asottile/pyupgrade
rev: v3.10.1
hooks:
- id: pyupgrade
args: [--py310-plus, --keep-runtime-typing]

- repo: https://github.com/shellcheck-py/shellcheck-py
rev: v0.9.0.5
hooks:
Expand Down
6 changes: 3 additions & 3 deletions gplugins/database/db_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import hashlib
import os
import tempfile
from functools import lru_cache
from functools import cache

import boto3
import boto3.session
Expand Down Expand Up @@ -46,7 +46,7 @@ class Simulation(SQLModel, table=True):
angle: float


@lru_cache(maxsize=None)
@cache
def get_database_engine():
host = os.getenv("PS_HOST", "")
database = os.getenv("PS_DATABASE", "")
Expand All @@ -59,7 +59,7 @@ def get_database_engine():
)


@lru_cache(maxsize=None)
@cache
def s3_client():
return boto3.client("s3")

Expand Down
2 changes: 1 addition & 1 deletion gplugins/gmeep/get_material.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def get_material(

meep_name = material_name_to_meep[name]

if isinstance(meep_name, (int, float)):
if isinstance(meep_name, int | float):
# if material is only a number, we can return early regardless of dispersion
return mp.Medium(index=meep_name)

Expand Down
4 changes: 2 additions & 2 deletions gplugins/lumerical/write_sparameters_lumerical.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ def set_material(session, structure: str, material: MaterialSpec) -> None:
"""
if isinstance(material, str):
session.setnamed(structure, "material", material)
elif isinstance(material, (int, float)):
elif isinstance(material, int | float):
session.setnamed(structure, "index", material)
elif isinstance(material, complex):
mat = session.addmaterial("(n,k) Material")
session.setmaterial(mat, "Refractive Index", material.real)
session.setmaterial(mat, "Imaginary Refractive Index", material.imag)
session.setnamed(structure, "material", mat)
elif isinstance(material, (tuple, list)):
elif isinstance(material, tuple | list):
if len(material) != 2:
raise ValueError(
"Complex material requires a tuple or list of two numbers "
Expand Down
12 changes: 5 additions & 7 deletions gplugins/sax/read.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import pathlib
from functools import partial
from typing import Literal, Union
from typing import Literal

import gdsfactory as gf
import jax
Expand All @@ -20,7 +20,7 @@

wl_cband = np.linspace(1.500, 1.600, 128)

PathType = Union[str, pathlib.Path]
PathType = str | pathlib.Path

Simulator = Literal["lumerical", "meep", "tidy3d"]

Expand All @@ -29,7 +29,6 @@ def model_from_npz(
filepath: PathType | np.ndarray,
xkey: str = "wavelengths",
xunits: float = 1,
prefix: str = "s",
) -> Model:
"""Returns a SAX Sparameters Model from a npz file.
Expand All @@ -40,10 +39,9 @@ def model_from_npz(
wl: wavelength to interpolate (um).
xkey: key for wavelengths in file.
xunits: x units in um from the loaded file (um). 1 means 1um.
prefix: for the sparameters column names in file.
"""
sp = np.load(filepath) if isinstance(filepath, (pathlib.Path, str)) else filepath
sp = np.load(filepath) if isinstance(filepath, pathlib.Path | str) else filepath
keys = list(sp.keys())

if xkey not in keys:
Expand All @@ -65,8 +63,8 @@ def model(wl: Float = wl):
for key in sp:
if not key.startswith("wav"):
port_mode0, port_mode1 = key.split(",")
port0, mode0 = port_mode0.split("@")
port1, mode1 = port_mode1.split("@")
port0, _ = port_mode0.split("@")
port1, _ = port_mode1.split("@")
S[(port0, port1)] = jnp.interp(wl, x, sp.get(key, zero))

return S
Expand Down
2 changes: 1 addition & 1 deletion gplugins/schematic_editor/circuitviz.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def viz_bk(
if fig is None:
fig = bp.figure()

if isinstance(netlist, (PicYamlConfiguration, SchematicConfiguration)):
if isinstance(netlist, PicYamlConfiguration | SchematicConfiguration):
objs = viz_netlist(netlist, instances, **kwargs)
else:
objs = netlist
Expand Down
2 changes: 1 addition & 1 deletion gplugins/tidy3d/materials.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def get_medium(
name_or_index.lower() if isinstance(name_or_index, str) else name_or_index
)

if isinstance(name_or_index, (int, float)):
if isinstance(name_or_index, int | float):
m = td.Medium(permittivity=name_or_index**2)
elif name_or_index in material_name_to_medium:
m = material_name_to_medium[name_or_index]
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@ select = [
"F", # pyflakes
"I", # isort
"C", # flake8-comprehensions
"B" # flake8-bugbear
"B", # flake8-bugbear
"UP"
]

[tool.ruff.per-file-ignores]
Expand Down

0 comments on commit 9d20ae7

Please sign in to comment.