From 284153ef2e2e40014656fbfeb254c05f3a8c61e8 Mon Sep 17 00:00:00 2001 From: Jennifer Taylor Date: Fri, 17 Feb 2023 03:32:27 +0000 Subject: [PATCH] Fix type errors with newest mypy. --- bemani/data/triggers.py | 2 +- bemani/format/afp/blend/blend.py | 27 +++++++++------------------ bemani/format/afp/blend/blendcpp.pyi | 2 +- bemani/format/afp/blend/blendcpp.pyx | 2 +- bemani/format/afp/container.py | 2 +- bemani/format/afp/render.py | 4 ++-- bemani/format/ifs.py | 2 +- bemani/utils/afputils.py | 8 ++++---- bemani/utils/assetparse.py | 2 +- 9 files changed, 21 insertions(+), 30 deletions(-) diff --git a/bemani/data/triggers.py b/bemani/data/triggers.py index ba22e89..ede984c 100644 --- a/bemani/data/triggers.py +++ b/bemani/data/triggers.py @@ -1,5 +1,5 @@ from datetime import datetime -from discord_webhook import DiscordWebhook, DiscordEmbed # type: ignore +from discord_webhook import DiscordWebhook, DiscordEmbed from typing import Dict from bemani.common.constants import GameConstants, BroadcastConstants diff --git a/bemani/format/afp/blend/blend.py b/bemani/format/afp/blend/blend.py index 6fd509e..594c34b 100644 --- a/bemani/format/afp/blend/blend.py +++ b/bemani/format/afp/blend/blend.py @@ -1,6 +1,6 @@ import multiprocessing import signal -from PIL import Image # type: ignore +from PIL import Image from typing import Any, Callable, List, Optional, Sequence, Union from ..types import Color, HSL, Matrix, Point, AAMode @@ -580,7 +580,7 @@ def affine_composite( cores = multiprocessing.cpu_count() if single_threaded or cores < 2: # Get the data in an easier to manipulate and faster to update fashion. - imgbytes = bytearray(img.tobytes("raw", "RGBA")) + imgbytearray = bytearray(img.tobytes("raw", "RGBA")) texbytes = texture.tobytes("raw", "RGBA") if mask: alpha = mask.split()[-1] @@ -593,7 +593,7 @@ def affine_composite( for imgx in range(minx, maxx): # Determine offset imgoff = (imgx + (imgy * imgwidth)) * 4 - imgbytes[imgoff : (imgoff + 4)] = pixel_renderer( + imgbytearray[imgoff : (imgoff + 4)] = pixel_renderer( imgx, imgy, imgwidth, @@ -607,13 +607,13 @@ def affine_composite( mult_color, hsl_shift, blendfunc, - imgbytes, + imgbytearray, texbytes, maskbytes, aa_mode, ) - img = Image.frombytes("RGBA", (imgwidth, imgheight), bytes(imgbytes)) + img = Image.frombytes("RGBA", (imgwidth, imgheight), bytes(imgbytearray)) else: imgbytes = img.tobytes("raw", "RGBA") texbytes = texture.tobytes("raw", "RGBA") @@ -792,15 +792,6 @@ def perspective_composite( # This texture is entirely off of the screen. return img - # Get the data in an easier to manipulate and faster to update fashion. - imgbytes = bytearray(img.tobytes("raw", "RGBA")) - texbytes = texture.tobytes("raw", "RGBA") - if mask: - alpha = mask.split()[-1] - maskbytes = alpha.tobytes("raw", "L") - else: - maskbytes = None - def perspective_inverse(imgpoint: Point) -> Optional[Point]: # Calculate the texture coordinate with our perspective interpolation. texdiv = inverse_matrix.multiply_point(imgpoint) @@ -812,7 +803,7 @@ def perspective_composite( cores = multiprocessing.cpu_count() if single_threaded or cores < 2: # Get the data in an easier to manipulate and faster to update fashion. - imgbytes = bytearray(img.tobytes("raw", "RGBA")) + imgbytearray = bytearray(img.tobytes("raw", "RGBA")) texbytes = texture.tobytes("raw", "RGBA") if mask: alpha = mask.split()[-1] @@ -825,7 +816,7 @@ def perspective_composite( for imgx in range(minx, maxx): # Determine offset imgoff = (imgx + (imgy * imgwidth)) * 4 - imgbytes[imgoff : (imgoff + 4)] = pixel_renderer( + imgbytearray[imgoff : (imgoff + 4)] = pixel_renderer( imgx, imgy, imgwidth, @@ -839,13 +830,13 @@ def perspective_composite( mult_color, hsl_shift, blendfunc, - imgbytes, + imgbytearray, texbytes, maskbytes, aa_mode, ) - img = Image.frombytes("RGBA", (imgwidth, imgheight), bytes(imgbytes)) + img = Image.frombytes("RGBA", (imgwidth, imgheight), bytes(imgbytearray)) else: imgbytes = img.tobytes("raw", "RGBA") texbytes = texture.tobytes("raw", "RGBA") diff --git a/bemani/format/afp/blend/blendcpp.pyi b/bemani/format/afp/blend/blendcpp.pyi index e78d5cc..0fd753a 100644 --- a/bemani/format/afp/blend/blendcpp.pyi +++ b/bemani/format/afp/blend/blendcpp.pyi @@ -1,4 +1,4 @@ -from PIL import Image # type: ignore +from PIL import Image from typing import Optional from ..types import Color, HSL, Point, Matrix diff --git a/bemani/format/afp/blend/blendcpp.pyx b/bemani/format/afp/blend/blendcpp.pyx index d7b2cd3..e739917 100644 --- a/bemani/format/afp/blend/blendcpp.pyx +++ b/bemani/format/afp/blend/blendcpp.pyx @@ -1,5 +1,5 @@ import multiprocessing -from PIL import Image # type: ignore +from PIL import Image from typing import Optional, Tuple from ..types import Color, HSL, Matrix, Point, AAMode diff --git a/bemani/format/afp/container.py b/bemani/format/afp/container.py index 808c0f8..96e748e 100644 --- a/bemani/format/afp/container.py +++ b/bemani/format/afp/container.py @@ -1,7 +1,7 @@ import io import os import struct -from PIL import Image # type: ignore +from PIL import Image from typing import Any, Dict, List, Optional, Tuple from bemani.format.dxt import DXTBuffer diff --git a/bemani/format/afp/render.py b/bemani/format/afp/render.py index 1258f3f..49d2d71 100644 --- a/bemani/format/afp/render.py +++ b/bemani/format/afp/render.py @@ -1,5 +1,5 @@ from typing import Any, Dict, Generator, List, Set, Tuple, Optional, Union -from PIL import Image # type: ignore +from PIL import Image from .blend import affine_composite, perspective_composite from .swf import ( @@ -85,7 +85,7 @@ class RegisteredShape: self.tex_points: List[Point] = tex_points self.tex_colors: List[Color] = tex_colors self.draw_params: List[DrawParams] = draw_params - self.rectangle: Optional[Image.image] = None + self.rectangle: Optional[Image.Image] = None @property def reference(self) -> str: diff --git a/bemani/format/ifs.py b/bemani/format/ifs.py index 7455286..804ba23 100644 --- a/bemani/format/ifs.py +++ b/bemani/format/ifs.py @@ -2,7 +2,7 @@ import hashlib import io import os import struct -from PIL import Image # type: ignore +from PIL import Image from typing import Callable, Dict, List, Optional, Tuple from bemani.format.dxt import DXTBuffer diff --git a/bemani/utils/afputils.py b/bemani/utils/afputils.py index b451289..ab5c145 100644 --- a/bemani/utils/afputils.py +++ b/bemani/utils/afputils.py @@ -7,7 +7,7 @@ import os import os.path import sys import textwrap -from PIL import Image, ImageDraw # type: ignore +from PIL import Image, ImageDraw from typing import Any, Dict, List, Optional, Tuple, TypeVar from bemani.format.afp import ( @@ -555,8 +555,8 @@ def load_containers( # Load file, register it. fdata = ifsfile.read_file(fname) - tex = Image.open(io.BytesIO(fdata)) - renderer.add_texture(texname, tex) + teximg = Image.open(io.BytesIO(fdata)) + renderer.add_texture(texname, teximg) if verbose: print( @@ -872,7 +872,7 @@ def render_path( # Write all the frames out in one file. duration = renderer.compute_path_frame_duration(path) frames = renderer.compute_path_frames(path) - images: List[Image] = [] + images: List[Image.Image] = [] for i, img in enumerate( renderer.render_path( path, diff --git a/bemani/utils/assetparse.py b/bemani/utils/assetparse.py index 559cb8c..9f34a5e 100644 --- a/bemani/utils/assetparse.py +++ b/bemani/utils/assetparse.py @@ -3,7 +3,7 @@ import argparse import os import xml.etree.ElementTree as ET -from PIL import Image # type: ignore +from PIL import Image from typing import Dict, Optional from bemani.common import GameConstants, VersionConstants