Skip to content

Commit

Permalink
Wrap unions in NewType to allow setattr
Browse files Browse the repository at this point in the history
This fixes Python 3.6 and 3.9 compatibility

Backported from 9a10cfe
  • Loading branch information
tulir committed Oct 27, 2020
1 parent 6fdd648 commit 3a4027e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion mautrix/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
__version__ = "0.7.13"
__version__ = "0.7.14"
__author__ = "Tulir Asokan <[email protected]>"
__all__ = ["api", "appservice", "bridge", "client", "crypto", "errors", "util", "types"]
5 changes: 3 additions & 2 deletions mautrix/types/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
from typing import Union, Optional, List
from typing import Union, Optional, List, NewType
from attr import dataclass
import attr

Expand Down Expand Up @@ -93,7 +93,8 @@ class PhoneIdentifier(SerializableAttrs['PhoneIdentifier']):
type: UserIdentifierType = UserIdentifierType.PHONE


UserIdentifier = Union[MatrixUserIdentifier, ThirdPartyIdentifier, PhoneIdentifier]
UserIdentifier = NewType('UserIdentifier',
Union[MatrixUserIdentifier, ThirdPartyIdentifier, PhoneIdentifier])


@deserializer(UserIdentifier)
Expand Down
5 changes: 3 additions & 2 deletions mautrix/types/event/encrypted.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
from typing import Optional, Dict, Union
from typing import Optional, Dict, Union, NewType
from enum import IntEnum, Enum
from attr import dataclass
import attr
Expand Down Expand Up @@ -73,7 +73,8 @@ def relates_to(self, relates_to: RelatesTo) -> None:
self._relates_to = relates_to


EncryptedEventContent = Union[EncryptedOlmEventContent, EncryptedMegolmEventContent]
EncryptedEventContent = NewType('EncryptedEventContent',
Union[EncryptedOlmEventContent, EncryptedMegolmEventContent])


@deserializer(EncryptedEventContent)
Expand Down

0 comments on commit 3a4027e

Please sign in to comment.