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:
Sybren A. Stüvel 2019-01-03 12:07:05 +01:00
parent 6d2e6efa13
commit c4de4e9990
7 changed files with 26 additions and 21 deletions

View File

@ -511,7 +511,7 @@ if system == "win32":
_get_win_folder = _get_win_folder_with_pywin32
except ImportError:
try:
from ctypes import windll
from ctypes import windll # type: ignore
_get_win_folder = _get_win_folder_with_ctypes
except ImportError:
try:

View File

@ -23,6 +23,7 @@ import traceback
import concurrent.futures
import logging
import gc
import typing
import bpy
@ -238,7 +239,7 @@ class AsyncModalOperatorMixin:
self._stop_async_task()
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."""
self.log.debug('Setting up a new task %r, so any existing task must be stopped', async_task)

View File

@ -445,7 +445,8 @@ class FLAMENCO_OT_render(async_loop.AsyncModalOperatorMixin,
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.
Returns the path of the destination blend file.

View File

@ -96,18 +96,18 @@ class CloudPath(pathlib.PurePosixPath):
def project_uuid(self) -> str:
assert self.parts[0] == '/'
if len(self.parts) <= 1:
return None
return ''
return self.parts[1]
@property
def node_uuids(self) -> list:
def node_uuids(self) -> tuple:
assert self.parts[0] == '/'
return self.parts[2:]
@property
def node_uuid(self) -> str:
if len(self.parts) <= 2:
return None
return ''
return self.parts[-1]

View File

@ -25,6 +25,7 @@ import functools
import logging
import pathlib
import tempfile
import typing
import shutil
import bpy
@ -100,7 +101,7 @@ async def find_sync_group_id(home_project_id: str,
user_id: 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.
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:
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
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:
log.info("Sync folder for Blender version %s doesn't exist, "
"and not creating it either.", blender_version)
return sync_group['_id'], None
return 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'
log = logging.getLogger('bpy.ops.%s' % bl_idname)
home_project_id = None
sync_group_id = None # top-level sync group node ID
sync_group_versioned_id = None # sync group node ID for the given Blender version.
home_project_id = ''
sync_group_id = '' # top-level sync group node ID
sync_group_versioned_id = '' # sync group node ID for the given Blender version.
action = bpy.props.EnumProperty(
items=[
@ -387,12 +388,12 @@ class PILLAR_OT_sync(pillar.PillarOperatorMixin,
"""Loads files from the Pillar server."""
# 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'},
'There are no synced Blender settings in your Blender Cloud.')
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.blender_version)
return

View File

@ -59,17 +59,17 @@ class BlenderCloudBrowser(pillar.PillarOperatorMixin,
project_name = ''
# 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.
menu_item_stack = []
menu_item_stack = [] # type: typing.List[menu_item_mod.MenuItem]
timer = None
log = logging.getLogger('%s.BlenderCloudBrowser' % __name__)
_menu_item_lock = threading.Lock()
current_display_content = [] # list of MenuItems currently displayed
loaded_images = set()
current_display_content = [] # type: typing.List[menu_item_mod.MenuItem]
loaded_images = set() # type: typing.Set[str]
thumbnails_cache = ''
maximized_area = False
@ -278,7 +278,8 @@ class BlenderCloudBrowser(pillar.PillarOperatorMixin,
# Just make this thread-safe to be on the safe side.
with self._menu_item_lock:
self.current_display_content.append(menu_item)
self.loaded_images.add(menu_item.icon.filepath_raw)
if menu_item.icon is not None:
self.loaded_images.add(menu_item.icon.filepath_raw)
self.sort_menu()

View File

@ -18,6 +18,7 @@
import json
import pathlib
import typing
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']:
if abs(num) < 1024:
return '%.1f %s%s' % (num, unit, suffix)
num /= 1024
num //= 1024
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.
Returns the path that contains the file, or None if not found.