Skip to content

Commit

Permalink
TYP: fix typing
Browse files Browse the repository at this point in the history
  • Loading branch information
neutrinoceros committed Jan 7, 2022
1 parent 714dfd4 commit 0146479
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 27 deletions.
4 changes: 2 additions & 2 deletions yt/data_objects/static_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
unit_system_registry,
)
from yt.units.yt_array import YTArray, YTQuantity
from yt.utilities.configure import configuration_callbacks
from yt.utilities.configure import YTConfig, configuration_callbacks
from yt.utilities.cosmology import Cosmology
from yt.utilities.exceptions import (
YTFieldNotFound,
Expand Down Expand Up @@ -77,7 +77,7 @@
_ds_store: Optional[ParameterFileStore] = None


def _setup_ds_store(ytcfg):
def _setup_ds_store(ytcfg: YTConfig) -> None:
global _ds_store
_ds_store = ParameterFileStore()

Expand Down
4 changes: 2 additions & 2 deletions yt/frontends/ramses/definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import re

from yt.funcs import mylog
from yt.utilities.configure import configuration_callbacks
from yt.utilities.configure import YTConfig, configuration_callbacks


def ramses_header(hvals):
Expand Down Expand Up @@ -70,7 +70,7 @@ def ramses_header(hvals):
}


def _setup_ramses_particle_families(ytcfg):
def _setup_ramses_particle_families(ytcfg: YTConfig) -> None:
if not ytcfg.has_section("ramses-families"):
return
for key in particle_families.keys():
Expand Down
4 changes: 2 additions & 2 deletions yt/mods.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from yt import *
from yt._maintenance.deprecation import issue_deprecation_warning
from yt.config import ytcfg, ytcfg_defaults
from yt.utilities.logger import _level
from yt.utilities.logger import ytLogger

issue_deprecation_warning(
"The yt.mods module is deprecated.", since="4.1.0", removal="4.2.0"
Expand All @@ -24,7 +24,7 @@
unparsed_args = __startup_tasks.unparsed_args


if _level >= int(ytcfg_defaults["yt"]["log_level"]): # type: ignore
if ytLogger.getEffectiveLevel() >= int(ytcfg_defaults["yt"]["log_level"]): # type: ignore
# This won't get displayed.
mylog.debug("Turning off NumPy error reporting")
np.seterr(all="ignore")
Expand Down
5 changes: 2 additions & 3 deletions yt/utilities/configure.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import os
from types import FunctionType
from typing import List
from typing import Callable, List

import toml
from more_itertools import always_iterable

from yt.utilities.configuration_tree import ConfigLeaf, ConfigNode

configuration_callbacks: List[FunctionType] = []
configuration_callbacks: List[Callable[["YTConfig"], None]] = []


def config_dir():
Expand Down
29 changes: 13 additions & 16 deletions yt/utilities/logger.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import logging
import sys
from typing import Callable, Optional

from yt.utilities.configure import configuration_callbacks
from yt.utilities.configure import YTConfig, configuration_callbacks

# from yt.config import ytcfg
_yt_sh: Optional[logging.StreamHandler] = None
_original_emitter: Optional[Callable[[logging.LogRecord], None]] = None


def set_log_level(level):
Expand Down Expand Up @@ -111,16 +113,11 @@ def colorize_logging():


def uncolorize_logging():
global original_emitter
try:
global _original_emitter, _yt_sh
if None not in (_original_emitter, _yt_sh):
f = logging.Formatter(ufstring)
ytLogger.handlers[0].setFormatter(f)
yt_sh.emit = original_emitter
except NameError:
# yt_sh and original_emitter are not defined because
# suppress_stream_logging is True, so we continue since there is nothing
# to uncolorize
pass
_yt_sh.emit = _original_emitter


def disable_stream_logging():
Expand All @@ -130,10 +127,10 @@ def disable_stream_logging():
ytLogger.addHandler(h)


def _runtime_configuration(ytcfg):
def _runtime_configuration(ytcfg: YTConfig) -> None:
# only run this at the end of yt.__init__, after yt.config.ytcfg was instanciated

global original_emitter
global _original_emitter, _yt_sh

if ytcfg.get("yt", "stdout_stream_logging"):
stream = sys.stdout
Expand All @@ -145,16 +142,16 @@ def _runtime_configuration(ytcfg):
if ytcfg.get("yt", "suppress_stream_logging"):
disable_stream_logging()
else:
yt_sh = logging.StreamHandler(stream=stream)
_yt_sh = logging.StreamHandler(stream=stream)
# create formatter and add it to the handlers
formatter = logging.Formatter(ufstring)
yt_sh.setFormatter(formatter)
_yt_sh.setFormatter(formatter)
# add the handler to the logger
ytLogger.addHandler(yt_sh)
ytLogger.addHandler(_yt_sh)
ytLogger.setLevel(_level)
ytLogger.propagate = False

original_emitter = yt_sh.emit
_original_emitter = _yt_sh.emit

if ytcfg.get("yt", "colored_logs"):
colorize_logging()
Expand Down
4 changes: 2 additions & 2 deletions yt/visualization/volume_rendering/render_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from yt.geometry.grid_geometry_handler import GridIndex
from yt.geometry.oct_geometry_handler import OctreeIndex
from yt.utilities.amr_kdtree.api import AMRKDTree
from yt.utilities.configure import configuration_callbacks
from yt.utilities.configure import YTConfig, configuration_callbacks
from yt.utilities.lib.bounding_volume_hierarchy import BVH
from yt.utilities.lib.misc_utilities import zlines, zpoints
from yt.utilities.lib.octree_raytracing import OctreeRayTracing
Expand Down Expand Up @@ -42,7 +42,7 @@
mesh_construction: OptionalModule = NotAModule("pyembree")


def _setup_raytracing_engine(ytcfg):
def _setup_raytracing_engine(ytcfg: YTConfig) -> None:
global mesh_traversal, mesh_construction
try:
from yt.utilities.lib.embree_mesh import mesh_traversal # type: ignore
Expand Down

0 comments on commit 0146479

Please sign in to comment.