Skip to content

Commit bb03466

Browse files
authored
[Python] Fix code and format warnings (#4096)
- Format and sort __slots__ and __all__ - Replace soon to be deprecated datetime.utcnow - Update ruff - Better type annotations for the option module - Use f-strings instead of format specifiers - Fix dev dependency group in pyproject.toml
1 parent 0bc751e commit bb03466

25 files changed

Lines changed: 346 additions & 305 deletions

poetry.lock

Lines changed: 92 additions & 48 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ packages = [
1313
python = ">= 3.10, < 4.0"
1414
python-dateutil = "^2.9.0"
1515

16-
[tool.poetry.dev-dependencies]
16+
[tool.poetry.group.dev.dependencies]
1717
pytest = "^8.1.1"
18-
ruff = "^0.3.4"
18+
ruff = "^0.11.6"
1919

2020
[tool.pyright]
2121
reportMissingTypeStubs = false

src/fable-library-py/fable_library/async_builder.py

Lines changed: 15 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,11 @@ def __init__(self, msg: str | None = None) -> None:
3535

3636

3737
class _Listener(Protocol):
38-
def __call__(self, __state: Any | None = None) -> None:
39-
...
38+
def __call__(self, __state: Any | None = None) -> None: ...
4039

4140

4241
class CancellationToken:
43-
__slots__ = "cancelled", "listeners", "idx", "lock"
42+
__slots__ = "cancelled", "idx", "listeners", "lock"
4443

4544
def __init__(self, cancelled: bool = False):
4645
self.cancelled = cancelled
@@ -93,36 +92,29 @@ class IAsyncContext(Generic[_T]):
9392
__slots__ = ()
9493

9594
@abstractmethod
96-
def on_success(self, value: _T) -> None:
97-
...
95+
def on_success(self, value: _T) -> None: ...
9896

9997
@abstractmethod
100-
def on_error(self, error: Exception) -> None:
101-
...
98+
def on_error(self, error: Exception) -> None: ...
10299

103100
@abstractmethod
104-
def on_cancel(self, error: OperationCanceledError) -> None:
105-
...
101+
def on_cancel(self, error: OperationCanceledError) -> None: ...
106102

107103
@property
108104
@abstractmethod
109-
def trampoline(self) -> Trampoline:
110-
...
105+
def trampoline(self) -> Trampoline: ...
111106

112107
@trampoline.setter
113108
@abstractmethod
114-
def trampoline(self, val: Trampoline):
115-
...
109+
def trampoline(self, val: Trampoline): ...
116110

117111
@property
118112
@abstractmethod
119-
def cancel_token(self) -> CancellationToken:
120-
...
113+
def cancel_token(self) -> CancellationToken: ...
121114

122115
@cancel_token.setter
123116
@abstractmethod
124-
def cancel_token(self, val: CancellationToken):
125-
...
117+
def cancel_token(self, val: CancellationToken): ...
126118

127119
@staticmethod
128120
def create(
@@ -144,7 +136,7 @@ def empty_continuation(x: Any = None) -> None:
144136

145137

146138
class AnonymousAsyncContext(IAsyncContext[_T]):
147-
__slots__ = "_on_success", "_on_error", "_on_cancel", "_trampoline", "_cancel_token"
139+
__slots__ = "_cancel_token", "_on_cancel", "_on_error", "_on_success", "_trampoline"
148140

149141
def __init__(
150142
self,
@@ -199,7 +191,7 @@ class ScheduledItem:
199191

200192

201193
class Trampoline:
202-
__slots__ = "lock", "running", "call_count"
194+
__slots__ = "call_count", "lock", "running"
203195

204196
MaxTrampolineCallCount = 75 # Max recursion depth: 1000
205197

@@ -308,12 +300,10 @@ def delay() -> Async[_U]:
308300
return self.While(lambda: not done, self.Delay(delay))
309301

310302
@overload
311-
def Return(self) -> Async[None]:
312-
...
303+
def Return(self) -> Async[None]: ...
313304

314305
@overload
315-
def Return(self, value: _T) -> Async[_T]:
316-
...
306+
def Return(self, value: _T) -> Async[_T]: ...
317307

318308
def Return(self, value: Any = None) -> Async[Any]:
319309
return protected_return(value)
@@ -367,12 +357,10 @@ def compensation() -> None:
367357
return self.TryFinally(binder(resource), compensation)
368358

369359
@overload
370-
def While(self, guard: Callable[[], bool], computation: Async[Literal[None]]) -> Async[None]:
371-
...
360+
def While(self, guard: Callable[[], bool], computation: Async[Literal[None]]) -> Async[None]: ...
372361

373362
@overload
374-
def While(self, guard: Callable[[], bool], computation: Async[_T]) -> Async[_T]:
375-
...
363+
def While(self, guard: Callable[[], bool], computation: Async[_T]) -> Async[_T]: ...
376364

377365
def While(self, guard: Callable[[], bool], computation: Async[Any]) -> Async[Any]:
378366
if guard():

src/fable-library-py/fable_library/big_int.py

Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -264,67 +264,67 @@ def try_parse(string: str, def_value: FSharpRef[int]) -> bool:
264264

265265
__all__ = [
266266
"BigInteger",
267+
"abs",
268+
"add",
267269
"compare",
270+
"divide",
268271
"equals",
269-
"abs",
270-
"sign",
272+
"from_int32",
273+
"from_int64",
274+
"from_one",
275+
"from_string",
276+
"from_zero",
277+
"get_is_even",
278+
"get_is_one",
279+
"get_is_power_of_two",
280+
"get_is_zero",
281+
"get_minus_one",
282+
"get_one",
283+
"get_sign",
284+
"get_zero",
285+
"is_even_integer",
286+
"is_negative",
287+
"is_odd_integer",
288+
"is_positive",
289+
"is_pow2",
271290
"max",
272291
"min",
273-
"add",
274-
"subtract",
275292
"multiply",
276-
"divide",
277-
"remainder",
278293
"negate",
279-
"op_unary_negation",
280-
"op_logical_not",
281-
"op_unary_plus",
282294
"op_addition",
283-
"op_subtraction",
284-
"op_multiply",
285-
"op_division",
286-
"op_modulus",
287-
"op_right_shift",
288-
"op_left_shift",
289295
"op_bitwise_and",
290296
"op_bitwise_or",
297+
"op_division",
298+
"op_equality",
291299
"op_exclusive_or",
292-
"op_less_than",
293-
"op_less_than_or_equal",
294300
"op_greater_than",
295301
"op_greater_than_or_equal",
296-
"op_equality",
297302
"op_inequality",
298-
"get_zero",
299-
"get_one",
300-
"get_minus_one",
301-
"get_is_zero",
302-
"get_is_one",
303-
"get_is_even",
304-
"get_is_power_of_two",
305-
"get_sign",
306-
"is_negative",
307-
"is_positive",
308-
"is_even_integer",
309-
"is_odd_integer",
310-
"is_pow2",
311-
"from_zero",
312-
"from_one",
313-
"from_int32",
314-
"from_int64",
315-
"from_string",
303+
"op_left_shift",
304+
"op_less_than",
305+
"op_less_than_or_equal",
306+
"op_logical_not",
307+
"op_modulus",
308+
"op_multiply",
309+
"op_right_shift",
310+
"op_subtraction",
311+
"op_unary_negation",
312+
"op_unary_plus",
313+
"parse",
314+
"remainder",
315+
"sign",
316+
"subtract",
317+
"to_byte",
316318
"to_decimal",
317319
"to_double",
318-
"to_single",
319-
"to_uint64",
320-
"to_int64",
321-
"to_uint32",
322-
"to_int32",
323-
"to_uint16",
324320
"to_int16",
325-
"to_byte",
321+
"to_int32",
322+
"to_int64",
326323
"to_sbyte",
324+
"to_single",
327325
"to_string",
328-
"parse",
326+
"to_uint16",
327+
"to_uint32",
328+
"to_uint64",
329329
"try_parse",
330330
]

src/fable-library-py/fable_library/bit_converter.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -106,26 +106,26 @@ def is_little_endian() -> bool:
106106

107107

108108
__all__ = [
109+
"double_to_int64bits",
110+
"get_bytes_boolean",
109111
"get_bytes_char",
112+
"get_bytes_double",
110113
"get_bytes_int16",
111-
"get_bytes_uint16",
112114
"get_bytes_int32",
113-
"get_bytes_uint32",
114115
"get_bytes_int64",
115-
"get_bytes_uint64",
116-
"get_bytes_boolean",
117116
"get_bytes_single",
118-
"get_bytes_double",
117+
"get_bytes_uint16",
118+
"get_bytes_uint32",
119+
"get_bytes_uint64",
119120
"int64bits_to_double",
120-
"double_to_int64bits",
121+
"is_little_endian",
121122
"to_boolean",
122123
"to_char",
124+
"to_double",
123125
"to_int16",
124-
"to_uint16",
125126
"to_int32",
126-
"to_uint64",
127127
"to_single",
128-
"to_double",
129128
"to_string",
130-
"is_little_endian",
129+
"to_uint16",
130+
"to_uint64",
131131
]

src/fable-library-py/fable_library/char.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -230,20 +230,20 @@ def parse(input: str) -> str:
230230
"char_code_at",
231231
"get_unicode_category",
232232
"is_control",
233-
"is_letter_or_digit",
234-
"is_letter",
235233
"is_digit",
236-
"is_upper",
234+
"is_high_surrogate",
235+
"is_letter",
236+
"is_letter_or_digit",
237+
"is_low_surrogate",
237238
"is_lower",
238-
"is_separator",
239-
"is_punctuation",
240239
"is_number",
241-
"is_symbol",
240+
"is_punctuation",
241+
"is_separator",
242242
"is_separator",
243-
"is_white_space",
244243
"is_surrogate",
245-
"is_low_surrogate",
246-
"is_high_surrogate",
247244
"is_surrogate_pair",
245+
"is_symbol",
246+
"is_upper",
247+
"is_white_space",
248248
"parse",
249249
]

0 commit comments

Comments
 (0)