Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use typing.get_type_hints for all python3 versions #2322

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 1 addition & 17 deletions pupil_src/shared_modules/gaze_mapping/notifications.py
Expand Up @@ -15,23 +15,7 @@

from typing_extensions import Self, TypedDict

if sys.version_info < (3, 9):

def get_type_hints(cls):
return cls.__annotations__

else:
# Starting in Python 3.10, __annotations__ does no longer contain the annotations
# of the parent class. `_SerializedNamedTupleMixin.sanitize_serialized_dict`
# depends on the earlier implementation.
# We do not use `inspect.get_annotations()` as a replacement for two reasons:
# 1. It also does not include the base classes' annoations
# 2. The annotations might not be evaluated yet, containing `typing.ForwardRef`
# instances
#
# `typing.get_type_hints` implements the desired behavior but is only available in
# Python 3.9 or newer
from typing import get_type_hints
from typing import get_type_hints


# TODO: Consider extending this pattern for notifications through the entire codebase and/or replace with dataclasses with Python 3.7
Expand Down
Expand Up @@ -75,15 +75,12 @@ def _event_loop(
ipc_push_url: str,
topic_prefix: str = "shared_camera.",
):
with (
NetworkInterface(
topic_prefix=topic_prefix,
ipc_pub_url=ipc_pub_url,
ipc_sub_url=ipc_sub_url,
ipc_push_url=ipc_push_url,
) as network,
contextlib.suppress(KeyboardInterrupt),
):
with NetworkInterface(
topic_prefix=topic_prefix,
ipc_pub_url=ipc_pub_url,
ipc_sub_url=ipc_sub_url,
ipc_push_url=ipc_push_url,
) as network, contextlib.suppress(KeyboardInterrupt):
process_started_event.set()

camera_model = cm.Camera_Model.from_file(
Expand Down