Fixed some MyPy warnings
This includes using `''` instead of `None` in some cases where an empty string conveys 'nothing' equally well as `None`; in such cases keeping the type the same rather than switching to another type is preferred.
This commit is contained in:
parent
6d2e6efa13
commit
c4de4e9990
@ -511,7 +511,7 @@ if system == "win32":
|
|||||||
_get_win_folder = _get_win_folder_with_pywin32
|
_get_win_folder = _get_win_folder_with_pywin32
|
||||||
except ImportError:
|
except ImportError:
|
||||||
try:
|
try:
|
||||||
from ctypes import windll
|
from ctypes import windll # type: ignore
|
||||||
_get_win_folder = _get_win_folder_with_ctypes
|
_get_win_folder = _get_win_folder_with_ctypes
|
||||||
except ImportError:
|
except ImportError:
|
||||||
try:
|
try:
|
||||||
|
@ -23,6 +23,7 @@ import traceback
|
|||||||
import concurrent.futures
|
import concurrent.futures
|
||||||
import logging
|
import logging
|
||||||
import gc
|
import gc
|
||||||
|
import typing
|
||||||
|
|
||||||
import bpy
|
import bpy
|
||||||
|
|
||||||
@ -238,7 +239,7 @@ class AsyncModalOperatorMixin:
|
|||||||
self._stop_async_task()
|
self._stop_async_task()
|
||||||
context.window_manager.event_timer_remove(self.timer)
|
context.window_manager.event_timer_remove(self.timer)
|
||||||
|
|
||||||
def _new_async_task(self, async_task: asyncio.coroutine, future: asyncio.Future = None):
|
def _new_async_task(self, async_task: typing.Coroutine, future: asyncio.Future = None):
|
||||||
"""Stops the currently running async task, and starts another one."""
|
"""Stops the currently running async task, and starts another one."""
|
||||||
|
|
||||||
self.log.debug('Setting up a new task %r, so any existing task must be stopped', async_task)
|
self.log.debug('Setting up a new task %r, so any existing task must be stopped', async_task)
|
||||||
|
@ -445,7 +445,8 @@ class FLAMENCO_OT_render(async_loop.AsyncModalOperatorMixin,
|
|||||||
|
|
||||||
return filepath
|
return filepath
|
||||||
|
|
||||||
async def bat_pack(self, filepath: Path) -> (Path, typing.Optional[Path], typing.List[Path]):
|
async def bat_pack(self, filepath: Path) \
|
||||||
|
-> typing.Tuple[Path, typing.Optional[Path], typing.List[Path]]:
|
||||||
"""BAT-packs the blendfile to the destination directory.
|
"""BAT-packs the blendfile to the destination directory.
|
||||||
|
|
||||||
Returns the path of the destination blend file.
|
Returns the path of the destination blend file.
|
||||||
|
@ -96,18 +96,18 @@ class CloudPath(pathlib.PurePosixPath):
|
|||||||
def project_uuid(self) -> str:
|
def project_uuid(self) -> str:
|
||||||
assert self.parts[0] == '/'
|
assert self.parts[0] == '/'
|
||||||
if len(self.parts) <= 1:
|
if len(self.parts) <= 1:
|
||||||
return None
|
return ''
|
||||||
return self.parts[1]
|
return self.parts[1]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def node_uuids(self) -> list:
|
def node_uuids(self) -> tuple:
|
||||||
assert self.parts[0] == '/'
|
assert self.parts[0] == '/'
|
||||||
return self.parts[2:]
|
return self.parts[2:]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def node_uuid(self) -> str:
|
def node_uuid(self) -> str:
|
||||||
if len(self.parts) <= 2:
|
if len(self.parts) <= 2:
|
||||||
return None
|
return ''
|
||||||
|
|
||||||
return self.parts[-1]
|
return self.parts[-1]
|
||||||
|
|
||||||
|
@ -25,6 +25,7 @@ import functools
|
|||||||
import logging
|
import logging
|
||||||
import pathlib
|
import pathlib
|
||||||
import tempfile
|
import tempfile
|
||||||
|
import typing
|
||||||
import shutil
|
import shutil
|
||||||
|
|
||||||
import bpy
|
import bpy
|
||||||
@ -100,7 +101,7 @@ async def find_sync_group_id(home_project_id: str,
|
|||||||
user_id: str,
|
user_id: str,
|
||||||
blender_version: str,
|
blender_version: str,
|
||||||
*,
|
*,
|
||||||
may_create=True) -> str:
|
may_create=True) -> typing.Tuple[str, str]:
|
||||||
"""Finds the group node in which to store sync assets.
|
"""Finds the group node in which to store sync assets.
|
||||||
|
|
||||||
If the group node doesn't exist and may_create=True, it creates it.
|
If the group node doesn't exist and may_create=True, it creates it.
|
||||||
@ -122,7 +123,7 @@ async def find_sync_group_id(home_project_id: str,
|
|||||||
|
|
||||||
if not may_create and sync_group is None:
|
if not may_create and sync_group is None:
|
||||||
log.info("Sync folder doesn't exist, and not creating it either.")
|
log.info("Sync folder doesn't exist, and not creating it either.")
|
||||||
return None, None
|
return '', ''
|
||||||
|
|
||||||
# Find/create the sub-group for the requested Blender version
|
# Find/create the sub-group for the requested Blender version
|
||||||
try:
|
try:
|
||||||
@ -144,7 +145,7 @@ async def find_sync_group_id(home_project_id: str,
|
|||||||
if not may_create and sub_sync_group is None:
|
if not may_create and sub_sync_group is None:
|
||||||
log.info("Sync folder for Blender version %s doesn't exist, "
|
log.info("Sync folder for Blender version %s doesn't exist, "
|
||||||
"and not creating it either.", blender_version)
|
"and not creating it either.", blender_version)
|
||||||
return sync_group['_id'], None
|
return sync_group['_id'], ''
|
||||||
|
|
||||||
return sync_group['_id'], sub_sync_group['_id']
|
return sync_group['_id'], sub_sync_group['_id']
|
||||||
|
|
||||||
@ -203,9 +204,9 @@ class PILLAR_OT_sync(pillar.PillarOperatorMixin,
|
|||||||
bl_description = 'Synchronises Blender settings with Blender Cloud'
|
bl_description = 'Synchronises Blender settings with Blender Cloud'
|
||||||
|
|
||||||
log = logging.getLogger('bpy.ops.%s' % bl_idname)
|
log = logging.getLogger('bpy.ops.%s' % bl_idname)
|
||||||
home_project_id = None
|
home_project_id = ''
|
||||||
sync_group_id = None # top-level sync group node ID
|
sync_group_id = '' # top-level sync group node ID
|
||||||
sync_group_versioned_id = None # sync group node ID for the given Blender version.
|
sync_group_versioned_id = '' # sync group node ID for the given Blender version.
|
||||||
|
|
||||||
action = bpy.props.EnumProperty(
|
action = bpy.props.EnumProperty(
|
||||||
items=[
|
items=[
|
||||||
@ -387,12 +388,12 @@ class PILLAR_OT_sync(pillar.PillarOperatorMixin,
|
|||||||
"""Loads files from the Pillar server."""
|
"""Loads files from the Pillar server."""
|
||||||
|
|
||||||
# If the sync group node doesn't exist, offer a list of groups that do.
|
# If the sync group node doesn't exist, offer a list of groups that do.
|
||||||
if self.sync_group_id is None:
|
if not self.sync_group_id:
|
||||||
self.bss_report({'ERROR'},
|
self.bss_report({'ERROR'},
|
||||||
'There are no synced Blender settings in your Blender Cloud.')
|
'There are no synced Blender settings in your Blender Cloud.')
|
||||||
return
|
return
|
||||||
|
|
||||||
if self.sync_group_versioned_id is None:
|
if not self.sync_group_versioned_id:
|
||||||
self.bss_report({'ERROR'}, 'Therre are no synced Blender settings for version %s' %
|
self.bss_report({'ERROR'}, 'Therre are no synced Blender settings for version %s' %
|
||||||
self.blender_version)
|
self.blender_version)
|
||||||
return
|
return
|
||||||
|
@ -59,17 +59,17 @@ class BlenderCloudBrowser(pillar.PillarOperatorMixin,
|
|||||||
project_name = ''
|
project_name = ''
|
||||||
|
|
||||||
# This contains a stack of Node objects that lead up to the currently browsed node.
|
# This contains a stack of Node objects that lead up to the currently browsed node.
|
||||||
path_stack = []
|
path_stack = [] # type: typing.List[pillarsdk.Node]
|
||||||
|
|
||||||
# This contains a stack of MenuItem objects that lead up to the currently browsed node.
|
# This contains a stack of MenuItem objects that lead up to the currently browsed node.
|
||||||
menu_item_stack = []
|
menu_item_stack = [] # type: typing.List[menu_item_mod.MenuItem]
|
||||||
|
|
||||||
timer = None
|
timer = None
|
||||||
log = logging.getLogger('%s.BlenderCloudBrowser' % __name__)
|
log = logging.getLogger('%s.BlenderCloudBrowser' % __name__)
|
||||||
|
|
||||||
_menu_item_lock = threading.Lock()
|
_menu_item_lock = threading.Lock()
|
||||||
current_display_content = [] # list of MenuItems currently displayed
|
current_display_content = [] # type: typing.List[menu_item_mod.MenuItem]
|
||||||
loaded_images = set()
|
loaded_images = set() # type: typing.Set[str]
|
||||||
thumbnails_cache = ''
|
thumbnails_cache = ''
|
||||||
maximized_area = False
|
maximized_area = False
|
||||||
|
|
||||||
@ -278,6 +278,7 @@ class BlenderCloudBrowser(pillar.PillarOperatorMixin,
|
|||||||
# Just make this thread-safe to be on the safe side.
|
# Just make this thread-safe to be on the safe side.
|
||||||
with self._menu_item_lock:
|
with self._menu_item_lock:
|
||||||
self.current_display_content.append(menu_item)
|
self.current_display_content.append(menu_item)
|
||||||
|
if menu_item.icon is not None:
|
||||||
self.loaded_images.add(menu_item.icon.filepath_raw)
|
self.loaded_images.add(menu_item.icon.filepath_raw)
|
||||||
|
|
||||||
self.sort_menu()
|
self.sort_menu()
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
|
|
||||||
import json
|
import json
|
||||||
import pathlib
|
import pathlib
|
||||||
|
import typing
|
||||||
|
|
||||||
|
|
||||||
def sizeof_fmt(num: int, suffix='B') -> str:
|
def sizeof_fmt(num: int, suffix='B') -> str:
|
||||||
@ -29,12 +30,12 @@ def sizeof_fmt(num: int, suffix='B') -> str:
|
|||||||
for unit in ['', 'Ki', 'Mi', 'Gi', 'Ti', 'Pi', 'Ei', 'Zi']:
|
for unit in ['', 'Ki', 'Mi', 'Gi', 'Ti', 'Pi', 'Ei', 'Zi']:
|
||||||
if abs(num) < 1024:
|
if abs(num) < 1024:
|
||||||
return '%.1f %s%s' % (num, unit, suffix)
|
return '%.1f %s%s' % (num, unit, suffix)
|
||||||
num /= 1024
|
num //= 1024
|
||||||
|
|
||||||
return '%.1f Yi%s' % (num, suffix)
|
return '%.1f Yi%s' % (num, suffix)
|
||||||
|
|
||||||
|
|
||||||
def find_in_path(path: pathlib.Path, filename: str) -> pathlib.Path:
|
def find_in_path(path: pathlib.Path, filename: str) -> typing.Optional[pathlib.Path]:
|
||||||
"""Performs a breadth-first search for the filename.
|
"""Performs a breadth-first search for the filename.
|
||||||
|
|
||||||
Returns the path that contains the file, or None if not found.
|
Returns the path that contains the file, or None if not found.
|
||||||
|
Reference in New Issue
Block a user