diff --git a/.efrocachemap b/.efrocachemap index dcc10618..5dd105db 100644 --- a/.efrocachemap +++ b/.efrocachemap @@ -3992,50 +3992,50 @@ "assets/src/ba_data/python/ba/_generated/__init__.py": "https://files.ballistica.net/cache/ba1/ee/e8/cad05aa531c7faf7ff7b96db7f6e", "assets/src/ba_data/python/ba/_generated/enums.py": "https://files.ballistica.net/cache/ba1/b2/e5/0ee0561e16257a32830645239f34", "ballisticacore-windows/Generic/BallisticaCore.ico": "https://files.ballistica.net/cache/ba1/89/c0/e32c7d2a35dc9aef57cc73b0911a", - "build/prefab/full/linux_arm64_gui/debug/ballisticacore": "https://files.ballistica.net/cache/ba1/e0/26/d75da83625028c8e357dac76a129", - "build/prefab/full/linux_arm64_gui/release/ballisticacore": "https://files.ballistica.net/cache/ba1/c8/b6/765c2a721efa98325a38da19d0eb", - "build/prefab/full/linux_arm64_server/debug/dist/ballisticacore_headless": "https://files.ballistica.net/cache/ba1/9d/41/fa5830815344e31c763a9aca92c3", - "build/prefab/full/linux_arm64_server/release/dist/ballisticacore_headless": "https://files.ballistica.net/cache/ba1/a7/88/703a619c457daa2c6c56824a6b1f", - "build/prefab/full/linux_x86_64_gui/debug/ballisticacore": "https://files.ballistica.net/cache/ba1/63/69/512992daf04e799a13970f512f50", - "build/prefab/full/linux_x86_64_gui/release/ballisticacore": "https://files.ballistica.net/cache/ba1/37/84/634ef47c0dd88bba66be916e901f", - "build/prefab/full/linux_x86_64_server/debug/dist/ballisticacore_headless": "https://files.ballistica.net/cache/ba1/3d/cd/dc73e62cfbfe0e3816bf4b120156", - "build/prefab/full/linux_x86_64_server/release/dist/ballisticacore_headless": "https://files.ballistica.net/cache/ba1/db/68/b611ae504cca1f9684a9efcd84c8", - "build/prefab/full/mac_arm64_gui/debug/ballisticacore": "https://files.ballistica.net/cache/ba1/99/38/07f48f1eae948ae3ab5cc6ce97c2", - "build/prefab/full/mac_arm64_gui/release/ballisticacore": "https://files.ballistica.net/cache/ba1/da/bd/bb8db3cef3c8e7a941b909b82643", - "build/prefab/full/mac_arm64_server/debug/dist/ballisticacore_headless": "https://files.ballistica.net/cache/ba1/50/66/1de4173401c8650157482c007ebf", - "build/prefab/full/mac_arm64_server/release/dist/ballisticacore_headless": "https://files.ballistica.net/cache/ba1/ee/bd/e621677535001ca6f32c15fd43a1", - "build/prefab/full/mac_x86_64_gui/debug/ballisticacore": "https://files.ballistica.net/cache/ba1/9a/0f/0f622bd6c5a6e54488e941200e4e", - "build/prefab/full/mac_x86_64_gui/release/ballisticacore": "https://files.ballistica.net/cache/ba1/d8/c4/35b68823ab81460311295a83886e", - "build/prefab/full/mac_x86_64_server/debug/dist/ballisticacore_headless": "https://files.ballistica.net/cache/ba1/61/16/3a1f6ebfef1f41fec9cd39fa17c2", - "build/prefab/full/mac_x86_64_server/release/dist/ballisticacore_headless": "https://files.ballistica.net/cache/ba1/ec/35/0543540e0b4706618f8cc841bb8f", - "build/prefab/full/windows_x86_gui/debug/BallisticaCore.exe": "https://files.ballistica.net/cache/ba1/fc/34/144ff7ce9492b762f84caa02724f", - "build/prefab/full/windows_x86_gui/release/BallisticaCore.exe": "https://files.ballistica.net/cache/ba1/cc/67/ac68cf919759eadfaced31f1efa4", - "build/prefab/full/windows_x86_server/debug/dist/BallisticaCoreHeadless.exe": "https://files.ballistica.net/cache/ba1/34/4c/51b13103e0f83181fe742f7c897b", - "build/prefab/full/windows_x86_server/release/dist/BallisticaCoreHeadless.exe": "https://files.ballistica.net/cache/ba1/bf/4d/cb9b9c778243f382c1d020afc9e4", - "build/prefab/lib/linux_arm64_gui/debug/libballisticacore_internal.a": "https://files.ballistica.net/cache/ba1/0a/2f/1f6cece221fc8823486168b51471", - "build/prefab/lib/linux_arm64_gui/release/libballisticacore_internal.a": "https://files.ballistica.net/cache/ba1/58/9a/cfa06df2e91eeb66012f56b742ee", - "build/prefab/lib/linux_arm64_server/debug/libballisticacore_internal.a": "https://files.ballistica.net/cache/ba1/95/3e/c381c2e24ea2cba45e08087e590a", - "build/prefab/lib/linux_arm64_server/release/libballisticacore_internal.a": "https://files.ballistica.net/cache/ba1/9c/82/a0ebe07c0e42e580f31bdb2b2467", - "build/prefab/lib/linux_x86_64_gui/debug/libballisticacore_internal.a": "https://files.ballistica.net/cache/ba1/6c/a8/3dfd910533e930f0fedaf09b1832", - "build/prefab/lib/linux_x86_64_gui/release/libballisticacore_internal.a": "https://files.ballistica.net/cache/ba1/eb/a7/1f75f95dba9f7629fd0ecb90ab06", - "build/prefab/lib/linux_x86_64_server/debug/libballisticacore_internal.a": "https://files.ballistica.net/cache/ba1/98/42/7a931a798523e9e65612692ca6a5", - "build/prefab/lib/linux_x86_64_server/release/libballisticacore_internal.a": "https://files.ballistica.net/cache/ba1/09/9a/7539564392bbc84953dd38c32c89", - "build/prefab/lib/mac_arm64_gui/debug/libballisticacore_internal.a": "https://files.ballistica.net/cache/ba1/74/bf/4afb42c9c93b880b92b579d88e8d", - "build/prefab/lib/mac_arm64_gui/release/libballisticacore_internal.a": "https://files.ballistica.net/cache/ba1/c8/d2/2eb632cf1f1b31e23c457f295b25", - "build/prefab/lib/mac_arm64_server/debug/libballisticacore_internal.a": "https://files.ballistica.net/cache/ba1/da/1b/23beed0f798a3a13dc96f7740893", - "build/prefab/lib/mac_arm64_server/release/libballisticacore_internal.a": "https://files.ballistica.net/cache/ba1/6b/e4/1faf417aadca88c585f91b8bba9a", - "build/prefab/lib/mac_x86_64_gui/debug/libballisticacore_internal.a": "https://files.ballistica.net/cache/ba1/5b/9a/9e327d1fa1597275cfffff54743a", - "build/prefab/lib/mac_x86_64_gui/release/libballisticacore_internal.a": "https://files.ballistica.net/cache/ba1/35/7c/968345ec1da69c03c347d5162fd2", - "build/prefab/lib/mac_x86_64_server/debug/libballisticacore_internal.a": "https://files.ballistica.net/cache/ba1/65/c5/e0bc13c4f8e08821c4762a75b625", - "build/prefab/lib/mac_x86_64_server/release/libballisticacore_internal.a": "https://files.ballistica.net/cache/ba1/18/46/efe29fa4080e4b1fd40f58195eeb", - "build/prefab/lib/windows/Debug_Win32/BallisticaCoreGenericInternal.lib": "https://files.ballistica.net/cache/ba1/b0/77/d5666111b1d63af507d6d1850ad3", - "build/prefab/lib/windows/Debug_Win32/BallisticaCoreGenericInternal.pdb": "https://files.ballistica.net/cache/ba1/2d/ca/2c69bc736839c9269fb7879de44b", - "build/prefab/lib/windows/Debug_Win32/BallisticaCoreHeadlessInternal.lib": "https://files.ballistica.net/cache/ba1/52/84/e251bf1f3500af6f551e5416b35f", - "build/prefab/lib/windows/Debug_Win32/BallisticaCoreHeadlessInternal.pdb": "https://files.ballistica.net/cache/ba1/dc/c1/fe656d715e77154926b28e3c1534", - "build/prefab/lib/windows/Release_Win32/BallisticaCoreGenericInternal.lib": "https://files.ballistica.net/cache/ba1/d6/68/5a7e7e12256a26d87e560b57e407", - "build/prefab/lib/windows/Release_Win32/BallisticaCoreGenericInternal.pdb": "https://files.ballistica.net/cache/ba1/c1/d4/90391eb116bd430db2d4bce90e90", - "build/prefab/lib/windows/Release_Win32/BallisticaCoreHeadlessInternal.lib": "https://files.ballistica.net/cache/ba1/d1/1e/41851108e6a4b7740c858e0cd2ab", - "build/prefab/lib/windows/Release_Win32/BallisticaCoreHeadlessInternal.pdb": "https://files.ballistica.net/cache/ba1/96/70/e686a917fc2efa8c8ad99e938567", + "build/prefab/full/linux_arm64_gui/debug/ballisticacore": "https://files.ballistica.net/cache/ba1/f4/32/9d4fcc5184cc84a3bcd491ec7192", + "build/prefab/full/linux_arm64_gui/release/ballisticacore": "https://files.ballistica.net/cache/ba1/60/be/d645a8c2894281041caaed88996a", + "build/prefab/full/linux_arm64_server/debug/dist/ballisticacore_headless": "https://files.ballistica.net/cache/ba1/a6/37/dc865c1fbe87adb9bc9c6deff002", + "build/prefab/full/linux_arm64_server/release/dist/ballisticacore_headless": "https://files.ballistica.net/cache/ba1/e2/02/d9edfae05b0939743e51ff8ae908", + "build/prefab/full/linux_x86_64_gui/debug/ballisticacore": "https://files.ballistica.net/cache/ba1/9d/f9/72c235af6f5f869f895e98da2271", + "build/prefab/full/linux_x86_64_gui/release/ballisticacore": "https://files.ballistica.net/cache/ba1/e7/b6/a0ee0372339a39b9b0e851e90960", + "build/prefab/full/linux_x86_64_server/debug/dist/ballisticacore_headless": "https://files.ballistica.net/cache/ba1/c1/eb/e032554943773d2d1eebe88ad7ab", + "build/prefab/full/linux_x86_64_server/release/dist/ballisticacore_headless": "https://files.ballistica.net/cache/ba1/3a/06/6d9b1d59e7a84a10ff12d9e7986d", + "build/prefab/full/mac_arm64_gui/debug/ballisticacore": "https://files.ballistica.net/cache/ba1/91/d8/b43991661b523cdcf16d2cc28530", + "build/prefab/full/mac_arm64_gui/release/ballisticacore": "https://files.ballistica.net/cache/ba1/f7/af/fa49caccf09056cdb4740f33bad2", + "build/prefab/full/mac_arm64_server/debug/dist/ballisticacore_headless": "https://files.ballistica.net/cache/ba1/c1/95/4bcb6ac9dbcf85f95e1d93fa9690", + "build/prefab/full/mac_arm64_server/release/dist/ballisticacore_headless": "https://files.ballistica.net/cache/ba1/7c/93/93c8f76ac399dfd15b0855471c0b", + "build/prefab/full/mac_x86_64_gui/debug/ballisticacore": "https://files.ballistica.net/cache/ba1/86/10/dd263a61886a23b9f070975b3d81", + "build/prefab/full/mac_x86_64_gui/release/ballisticacore": "https://files.ballistica.net/cache/ba1/fb/ad/4ea35be3c9ac3e84cf1d0dbe1d9e", + "build/prefab/full/mac_x86_64_server/debug/dist/ballisticacore_headless": "https://files.ballistica.net/cache/ba1/84/39/2434d512db771fe9b7e89ceaa134", + "build/prefab/full/mac_x86_64_server/release/dist/ballisticacore_headless": "https://files.ballistica.net/cache/ba1/2c/af/c8b0e5f68441ee3f105211790656", + "build/prefab/full/windows_x86_gui/debug/BallisticaCore.exe": "https://files.ballistica.net/cache/ba1/2c/e8/9944f707235323ca9ca0be3e372d", + "build/prefab/full/windows_x86_gui/release/BallisticaCore.exe": "https://files.ballistica.net/cache/ba1/8f/05/b0b13ed8da0e04c20168d85ff997", + "build/prefab/full/windows_x86_server/debug/dist/BallisticaCoreHeadless.exe": "https://files.ballistica.net/cache/ba1/fb/9e/0eb1802d0a709283946b8608a837", + "build/prefab/full/windows_x86_server/release/dist/BallisticaCoreHeadless.exe": "https://files.ballistica.net/cache/ba1/c9/5a/feaec46d12cecb311c2c68e5ae20", + "build/prefab/lib/linux_arm64_gui/debug/libballisticacore_internal.a": "https://files.ballistica.net/cache/ba1/15/7e/65c2b19ea93a259c53ce2f40f1a9", + "build/prefab/lib/linux_arm64_gui/release/libballisticacore_internal.a": "https://files.ballistica.net/cache/ba1/82/42/dc48db3497a332642837bf4b0b58", + "build/prefab/lib/linux_arm64_server/debug/libballisticacore_internal.a": "https://files.ballistica.net/cache/ba1/e8/39/cb8d0308e194f7009547fb36ef7d", + "build/prefab/lib/linux_arm64_server/release/libballisticacore_internal.a": "https://files.ballistica.net/cache/ba1/33/be/18a2ed8f42ff70a273d195e335a9", + "build/prefab/lib/linux_x86_64_gui/debug/libballisticacore_internal.a": "https://files.ballistica.net/cache/ba1/be/4c/9214c24d52ceab82babbfc087363", + "build/prefab/lib/linux_x86_64_gui/release/libballisticacore_internal.a": "https://files.ballistica.net/cache/ba1/1c/91/6ec90d4444e2d8104161361cd3c9", + "build/prefab/lib/linux_x86_64_server/debug/libballisticacore_internal.a": "https://files.ballistica.net/cache/ba1/a7/ce/cd9fa30993fb964b2f920b0a87c0", + "build/prefab/lib/linux_x86_64_server/release/libballisticacore_internal.a": "https://files.ballistica.net/cache/ba1/29/2b/ba8830a2bf981a1f1baa62b5941e", + "build/prefab/lib/mac_arm64_gui/debug/libballisticacore_internal.a": "https://files.ballistica.net/cache/ba1/73/16/1ffaf6dc1bed1f94ae855e72b55c", + "build/prefab/lib/mac_arm64_gui/release/libballisticacore_internal.a": "https://files.ballistica.net/cache/ba1/1b/0f/bc40ad4779100ff3a21133033ffe", + "build/prefab/lib/mac_arm64_server/debug/libballisticacore_internal.a": "https://files.ballistica.net/cache/ba1/c8/a1/7a5e3522a0630758319cd39cceb0", + "build/prefab/lib/mac_arm64_server/release/libballisticacore_internal.a": "https://files.ballistica.net/cache/ba1/9a/a4/dd5a0be067adbc67b2a1278840a7", + "build/prefab/lib/mac_x86_64_gui/debug/libballisticacore_internal.a": "https://files.ballistica.net/cache/ba1/ce/d4/6902395063514cf2a550fe258925", + "build/prefab/lib/mac_x86_64_gui/release/libballisticacore_internal.a": "https://files.ballistica.net/cache/ba1/f8/c1/d618c8d26e9f845791fc9f41e022", + "build/prefab/lib/mac_x86_64_server/debug/libballisticacore_internal.a": "https://files.ballistica.net/cache/ba1/46/ff/0671960fbe8e77599e55a590979b", + "build/prefab/lib/mac_x86_64_server/release/libballisticacore_internal.a": "https://files.ballistica.net/cache/ba1/8e/79/5f0e75b95aae11fa53b19fa3eb36", + "build/prefab/lib/windows/Debug_Win32/BallisticaCoreGenericInternal.lib": "https://files.ballistica.net/cache/ba1/0b/34/202a0f4892d35f23341f4ad8f661", + "build/prefab/lib/windows/Debug_Win32/BallisticaCoreGenericInternal.pdb": "https://files.ballistica.net/cache/ba1/20/c0/4a6cc65902a0b819589de1bb17be", + "build/prefab/lib/windows/Debug_Win32/BallisticaCoreHeadlessInternal.lib": "https://files.ballistica.net/cache/ba1/3d/c1/8eefaabc68e7246fa8cb7244147a", + "build/prefab/lib/windows/Debug_Win32/BallisticaCoreHeadlessInternal.pdb": "https://files.ballistica.net/cache/ba1/e0/10/50475bccb5df48c3375c55ff2160", + "build/prefab/lib/windows/Release_Win32/BallisticaCoreGenericInternal.lib": "https://files.ballistica.net/cache/ba1/1d/e5/defa913c57893c82307de7b5120c", + "build/prefab/lib/windows/Release_Win32/BallisticaCoreGenericInternal.pdb": "https://files.ballistica.net/cache/ba1/98/4b/5eba04f89559430fa20312df11e3", + "build/prefab/lib/windows/Release_Win32/BallisticaCoreHeadlessInternal.lib": "https://files.ballistica.net/cache/ba1/68/2f/cb56da2caabc1e3eca790e91d897", + "build/prefab/lib/windows/Release_Win32/BallisticaCoreHeadlessInternal.pdb": "https://files.ballistica.net/cache/ba1/8a/6c/e271ac59657aa6e7b510dde82879", "src/ballistica/generated/python_embedded/binding.inc": "https://files.ballistica.net/cache/ba1/6e/6f/004b696e9a13b083069374e4bb6a", "src/ballistica/generated/python_embedded/bootstrap.inc": "https://files.ballistica.net/cache/ba1/d3/db/e73d4dcf1280d5f677c3cf8b47c3" } \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index bd85df10..4b5b2e03 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,8 @@ -### 1.7.0 (20588, 2022-06-02) +### 1.7.1 (20594, 2022-06-03) +- V2 account logic fixes +- Polishing V2 web-based login flow + +### 1.7.0 (20591, 2022-06-02) - V2 accounts are now available (woohoo!). These are called 'BombSquad Accounts' in the account section. V2 accounts communicate with a completely new server and will be the foundation for lots of new functionality in the future. However they also function as a V1 account so existing functionality should still work. Note that the new 'workspaces' feature for V2-accounts is not yet enabled in this build, but it will be in the next few builds. Also note that account types such as GameCenter and Google-Play will be 'upgraded' to V2 accounts in the future so there is no need to try this out if you use one of those. But if you use device-accounts you might want to create yourself a V2 account, since device-accounts will remain V1-only (though you can link an old device-account to a v2-enabled account if you want to keep your progress). Getting a V2 account now also gives you a chance to reserve a nice account-tag before all the good ones are taken. - Legacy account subsystem has been renamed from `ba.app.accounts` to `ba.app.accounts_v1` - Added `ba.app.accounts_v2` subsystem for working with V2 accounts. diff --git a/assets/src/ba_data/python/bastd/ui/account/v2.py b/assets/src/ba_data/python/bastd/ui/account/v2.py index 9acc76a5..e8070507 100644 --- a/assets/src/ba_data/python/bastd/ui/account/v2.py +++ b/assets/src/ba_data/python/bastd/ui/account/v2.py @@ -24,7 +24,7 @@ class V2SignInWindow(ba.Window): def __init__(self, origin_widget: ba.Widget): self._width = 600 - self._height = 500 + self._height = 550 self._proxyid: Optional[str] = None self._proxykey: Optional[str] = None @@ -34,7 +34,7 @@ class V2SignInWindow(ba.Window): transition='in_scale', scale_origin_stack_offset=origin_widget.get_screen_space_center(), scale=(1.25 if uiscale is ba.UIScale.SMALL else - 1.0 if uiscale is ba.UIScale.MEDIUM else 0.85))) + 1.05 if uiscale is ba.UIScale.MEDIUM else 0.9))) self._loading_text = ba.textwidget( parent=self._root_widget, @@ -49,7 +49,7 @@ class V2SignInWindow(ba.Window): self._cancel_button = ba.buttonwidget( parent=self._root_widget, - position=(30, self._height - 55), + position=(30, self._height - 65), size=(130, 50), scale=0.8, label=ba.Lstr(resource='cancelText'), @@ -83,9 +83,11 @@ class V2SignInWindow(ba.Window): # Show link(s) the user can use to log in. address = _ba.get_master_server_address(version=2) + response.url + address_pretty = address.removeprefix('https://') + ba.textwidget( parent=self._root_widget, - position=(self._width * 0.5, self._height - 85), + position=(self._width * 0.5, self._height - 95), size=(0, 0), text=ba.Lstr( resource='accountSettingsWindow.v2LinkInstructionsText'), @@ -97,19 +99,19 @@ class V2SignInWindow(ba.Window): if is_browser_likely_available(): ba.buttonwidget(parent=self._root_widget, position=((self._width * 0.5 - button_width * 0.5), - self._height - 175), + self._height - 185), autoselect=True, size=(button_width, 60), - label=ba.Lstr(value=address), + label=ba.Lstr(value=address_pretty), color=(0.55, 0.5, 0.6), textcolor=(0.75, 0.7, 0.8), on_activate_call=lambda: ba.open_url(address)) qroffs = 0.0 else: ba.textwidget(parent=self._root_widget, - position=(self._width * 0.5, self._height - 135), + position=(self._width * 0.5, self._height - 145), size=(0, 0), - text=ba.Lstr(value=address), + text=ba.Lstr(value=address_pretty), flatness=1.0, maxwidth=self._width, scale=0.75, @@ -120,7 +122,7 @@ class V2SignInWindow(ba.Window): qr_size = 270 ba.imagewidget(parent=self._root_widget, position=(self._width * 0.5 - qr_size * 0.5, - self._height * 0.34 + qroffs - qr_size * 0.5), + self._height * 0.36 + qroffs - qr_size * 0.5), size=(qr_size, qr_size), texture=_ba.get_qrcode_texture(address)) diff --git a/src/ballistica/ballistica.cc b/src/ballistica/ballistica.cc index bd5c7c1e..e2fc4bbd 100644 --- a/src/ballistica/ballistica.cc +++ b/src/ballistica/ballistica.cc @@ -21,8 +21,8 @@ namespace ballistica { // These are set automatically via script; don't modify them here. -const int kAppBuildNumber = 20588; -const char* kAppVersion = "1.7.0"; +const int kAppBuildNumber = 20594; +const char* kAppVersion = "1.7.1"; // Our standalone globals. // These are separated out for easy access. diff --git a/tests/test_efro/test_dataclassio.py b/tests/test_efro/test_dataclassio.py index 29e644e0..64283aaa 100644 --- a/tests/test_efro/test_dataclassio.py +++ b/tests/test_efro/test_dataclassio.py @@ -67,6 +67,7 @@ def test_assign() -> None: nval: _NestedClass = field(default_factory=_NestedClass) enval: _EnumTest = _EnumTest.TEST1 oival: Optional[int] = None + oival2: int | None = None osval: Optional[str] = None obval: Optional[bool] = None ofval: Optional[float] = None @@ -120,6 +121,8 @@ def test_assign() -> None: 'test1', 'oival': 1, + 'oival2': + 1, 'osval': 'foo', 'obval': @@ -160,6 +163,7 @@ def test_assign() -> None: dataclass_from_dict( _TestClass, { 'oival': None, + 'oival2': None, 'osval': None, 'obval': None, 'ofval': None, @@ -173,6 +177,7 @@ def test_assign() -> None: dataclass_from_dict( _TestClass, { 'oival': 1, + 'oival2': 1, 'osval': 'foo', 'obval': True, 'ofval': 2.0, @@ -191,6 +196,10 @@ def test_assign() -> None: dataclass_from_dict(_TestClass, {'bval': 2}) with pytest.raises(TypeError): dataclass_from_dict(_TestClass, {'oival': 'foo'}) + with pytest.raises(TypeError): + dataclass_from_dict(_TestClass, {'oival2': 'foo'}) + dataclass_from_dict(_TestClass, {'oival2': None}) + dataclass_from_dict(_TestClass, {'oival2': 123}) with pytest.raises(TypeError): dataclass_from_dict(_TestClass, {'osval': 1}) with pytest.raises(TypeError): diff --git a/tools/efro/dataclassio/_inputter.py b/tools/efro/dataclassio/_inputter.py index 6948cbf8..34c1e5fe 100644 --- a/tools/efro/dataclassio/_inputter.py +++ b/tools/efro/dataclassio/_inputter.py @@ -11,6 +11,7 @@ from __future__ import annotations from enum import Enum import dataclasses import typing +import types import datetime from typing import TYPE_CHECKING, Generic, TypeVar @@ -78,7 +79,7 @@ class _Inputter(Generic[T]): f' \'{type(value).__name__}\' which is not.') return value - if origin is typing.Union: + if origin is typing.Union or origin is types.UnionType: # Currently, the only unions we support are None/Value # (translated from Optional), which we verified on prep. # So let's treat this as a simple optional case. diff --git a/tools/efro/dataclassio/_outputter.py b/tools/efro/dataclassio/_outputter.py index 1f68c988..e268d7dd 100644 --- a/tools/efro/dataclassio/_outputter.py +++ b/tools/efro/dataclassio/_outputter.py @@ -11,6 +11,7 @@ from __future__ import annotations from enum import Enum import dataclasses import typing +import types import datetime from typing import TYPE_CHECKING @@ -141,7 +142,7 @@ class _Outputter: f' found \'{type(value).__name__}\' which is not.') return value if self._create else None - if origin is typing.Union: + if origin is typing.Union or origin is types.UnionType: # Currently, the only unions we support are None/Value # (translated from Optional), which we verified on prep. # So let's treat this as a simple optional case. diff --git a/tools/efro/dataclassio/_prep.py b/tools/efro/dataclassio/_prep.py index dc576909..c6fd503f 100644 --- a/tools/efro/dataclassio/_prep.py +++ b/tools/efro/dataclassio/_prep.py @@ -12,6 +12,7 @@ import logging from enum import Enum import dataclasses import typing +import types import datetime from typing import TYPE_CHECKING, TypeVar, get_type_hints @@ -242,7 +243,7 @@ class PrepSession: origin = _get_origin(anntype) - if origin is typing.Union: + if origin is typing.Union or origin is types.UnionType: self.prep_union(cls, attrname, anntype, diff --git a/tools/efro/util.py b/tools/efro/util.py index 173853b2..d18e5050 100644 --- a/tools/efro/util.py +++ b/tools/efro/util.py @@ -24,7 +24,7 @@ except ModuleNotFoundError: if TYPE_CHECKING: import asyncio from efro.call import Call as Call # 'as Call' so we re-export. - from typing import Any, Callable, Optional, NoReturn + from typing import Any, Callable, NoReturn T = TypeVar('T') TVAL = TypeVar('TVAL') @@ -177,15 +177,15 @@ class DirtyBit: retry_interval: float = 5.0, use_lock: bool = False, auto_dirty_seconds: float = None, - min_update_interval: Optional[float] = None): + min_update_interval: float | None = None): curtime = time.time() self._retry_interval = retry_interval self._auto_dirty_seconds = auto_dirty_seconds self._min_update_interval = min_update_interval self._dirty = dirty - self._next_update_time: Optional[float] = (curtime if dirty else None) - self._last_update_time: Optional[float] = None - self._next_auto_dirty_time: Optional[float] = ( + self._next_update_time: float | None = (curtime if dirty else None) + self._last_update_time: float | None = None + self._next_auto_dirty_time: float | None = ( (curtime + self._auto_dirty_seconds) if (not dirty and self._auto_dirty_seconds is not None) else None) self._use_lock = use_lock @@ -476,7 +476,7 @@ def asserttype(obj: Any, typ: type[T]) -> T: return obj -def asserttype_o(obj: Any, typ: type[T]) -> Optional[T]: +def asserttype_o(obj: Any, typ: type[T]) -> T | None: """Return an object typed as a given optional type. Assert is used to check its actual type, so only use this when @@ -499,7 +499,7 @@ def checktype(obj: Any, typ: type[T]) -> T: return obj -def checktype_o(obj: Any, typ: type[T]) -> Optional[T]: +def checktype_o(obj: Any, typ: type[T]) -> T | None: """Return an object typed as a given optional type. Always checks the type at runtime with isinstance and throws a TypeError @@ -524,7 +524,7 @@ def warntype(obj: Any, typ: type[T]) -> T: return obj # type: ignore -def warntype_o(obj: Any, typ: type[T]) -> Optional[T]: +def warntype_o(obj: Any, typ: type[T]) -> T | None: """Return an object typed as a given type. Always checks the type at runtime and simply logs a warning if it is @@ -538,7 +538,7 @@ def warntype_o(obj: Any, typ: type[T]) -> Optional[T]: return obj # type: ignore -def assert_non_optional(obj: Optional[T]) -> T: +def assert_non_optional(obj: T | None) -> T: """Return an object with Optional typing removed. Assert is used to check its actual type, so only use this when @@ -548,7 +548,7 @@ def assert_non_optional(obj: Optional[T]) -> T: return obj -def check_non_optional(obj: Optional[T]) -> T: +def check_non_optional(obj: T | None) -> T: """Return an object with Optional typing removed. Always checks the actual type and throws a TypeError on failure. @@ -679,12 +679,12 @@ def set_canonical_module(module_globals: dict[str, Any], for name in names: obj = module_globals[name] existing = getattr(obj, '__module__', None) - if existing is not None and existing != modulename: - try: + try: + if existing is not None and existing != modulename: obj.__module__ = modulename - except Exception: - import logging - logging.warning( - 'set_canonical_module: unable to change __module__' - ' from %s to %s on %s object.', existing, modulename, - type(obj)) + except Exception: + import logging + logging.warning( + 'set_canonical_module: unable to change __module__' + " from '%s' to '%s' on %s object at '%s'.", existing, + modulename, type(obj), name)