Skip to content

Commit

Permalink
Improve typing
Browse files Browse the repository at this point in the history
  • Loading branch information
cphyc committed Dec 6, 2023
1 parent b93c0b4 commit 53a3e0a
Showing 1 changed file with 38 additions and 18 deletions.
56 changes: 38 additions & 18 deletions yt/frontends/ramses/particle_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import os
import struct
from itertools import chain, count
from typing import Any, Optional
from typing import TYPE_CHECKING, Any, Callable, Optional

import numpy as np

Expand All @@ -19,6 +19,9 @@
_read_part_csv_file_descriptor,
)

if TYPE_CHECKING:
from yt.frontends.ramses.data_structures import RAMSESDomainSubset

PARTICLE_HANDLERS: set[type["ParticleFileHandler"]] = set()


Expand All @@ -42,23 +45,40 @@ class ParticleFileHandler(abc.ABC, HandlerMixin):

_file_type = "particle"

# These properties are static properties
ptype: Optional[str] = None # The name to give to the particle type
fname: Optional[str] = None # The name of the file(s).
file_descriptor: Optional[str] = None # The name of the file descriptor (if any)

attrs: tuple[tuple[str, int, str], ...] # The attributes of the header
known_fields: Optional[
list[FieldKey]
] = None # A list of tuple containing the field name and its type
config_field: Optional[str] = None # Name of the config section (if any)

# These properties are computed dynamically
field_offsets = None # Mapping from field to offset in file
field_types = (
None # Mapping from field to the type of the data (float, integer, ...)
)
local_particle_count = None # The number of particle in the domain
## These properties are static
# The name to give to the particle type
ptype: str

# The name of the file(s).
fname: str

# The name of the file descriptor (if any)
file_descriptor: Optional[str] = None

# The attributes of the header
attrs: tuple[tuple[str, int, str], ...]

# A list of tuple containing the field name and its type
known_fields: list[FieldKey]

# The function to employ to read the file
reader: Callable[
["ParticleFileHandler", "RAMSESDomainSubset", list[tuple[str, str]], int],
dict[tuple[str, str], np.ndarray],
]

# Name of the config section (if any)
config_field: Optional[str] = None

## These properties are computed dynamically
# Mapping from field to offset in file
_field_offsets: dict[tuple[str, str], int]

# Mapping from field to the type of the data (float, integer, ...)
_field_types: dict[tuple[str, str], str]

# Number of particle in the domain
_local_particle_count: int

def __init_subclass__(cls, *args, **kwargs):
"""
Expand Down

0 comments on commit 53a3e0a

Please sign in to comment.