Skip to content

Commit 1e932e2

Browse files
dbrattliclaude
andcommitted
refactor(stdlib): drop redundant Emit attrs in Regex bindings
Strip [<Emit>] attributes that simply reproduce the default Fable codegen (positional-only IExports overloads with flags, string-key Match accessors, no-arg `end()`). Per BINDINGS_GUIDE.md and the Random.fs convention, [<Emit>] should only appear when it changes generated output (int casts, keyword args, list wraps). Also collapse the duplicate-literal short flag aliases ([<Literal>] let I = 2) into literal aliases of the long names ([<Literal>] let I = IGNORECASE) so the integer values live in one place. Generated Python is byte-identical for the affected sites; all 430 tests pass. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent ceb6b3c commit 1e932e2

1 file changed

Lines changed: 7 additions & 18 deletions

File tree

src/stdlib/Regex.fs

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ module Flags =
2424

2525
/// Case-insensitive matching. Alias for IGNORECASE.
2626
[<Literal>]
27-
let I = 2
27+
let I = IGNORECASE
2828

2929
/// Make ^ match at the beginning and $ at the end of each line. Short alias: M.
3030
/// See https://docs.python.org/3/library/re.html#re.MULTILINE
@@ -33,7 +33,7 @@ module Flags =
3333

3434
/// Make ^ match at the beginning and $ at the end of each line. Alias for MULTILINE.
3535
[<Literal>]
36-
let M = 8
36+
let M = MULTILINE
3737

3838
/// Make . match any character including newline. Short alias: S.
3939
/// See https://docs.python.org/3/library/re.html#re.DOTALL
@@ -42,7 +42,7 @@ module Flags =
4242

4343
/// Make . match any character including newline. Alias for DOTALL.
4444
[<Literal>]
45-
let S = 16
45+
let S = DOTALL
4646

4747
/// Restrict \w, \d, \s etc. to ASCII characters only. Short alias: A.
4848
/// See https://docs.python.org/3/library/re.html#re.ASCII
@@ -51,7 +51,7 @@ module Flags =
5151

5252
/// Restrict \w, \d, \s etc. to ASCII characters only. Alias for ASCII.
5353
[<Literal>]
54-
let A = 256
54+
let A = ASCII
5555

5656
/// Make \w, \W etc. locale-dependent (rarely needed). Short alias: L.
5757
/// See https://docs.python.org/3/library/re.html#re.LOCALE
@@ -60,7 +60,7 @@ module Flags =
6060

6161
/// Make \w, \W etc. locale-dependent. Alias for LOCALE.
6262
[<Literal>]
63-
let L = 4
63+
let L = LOCALE
6464

6565
/// Unicode character matching for \w, \W etc. (default in Python 3). Short alias: U.
6666
/// See https://docs.python.org/3/library/re.html#re.UNICODE
@@ -69,7 +69,7 @@ module Flags =
6969

7070
/// Unicode character matching for \w, \W etc. Alias for UNICODE.
7171
[<Literal>]
72-
let U = 32
72+
let U = UNICODE
7373

7474
/// Allow whitespace and comments in the pattern. Short alias: X.
7575
/// See https://docs.python.org/3/library/re.html#re.VERBOSE
@@ -78,7 +78,7 @@ module Flags =
7878

7979
/// Allow whitespace and comments in the pattern. Alias for VERBOSE.
8080
[<Literal>]
81-
let X = 64
81+
let X = VERBOSE
8282

8383
// ============================================================================
8484
// Match object
@@ -116,7 +116,6 @@ type Match() =
116116
/// Return the string matched by a named capturing group.
117117
/// Returns None if the group exists but did not participate in the match.
118118
/// See https://docs.python.org/3/library/re.html#re.Match.group
119-
[<Emit("$0.group($1)")>]
120119
member _.group(group: string) : string option = nativeOnly
121120

122121
/// Return a tuple of all subgroup strings (groups 1..N).
@@ -154,12 +153,10 @@ type Match() =
154153
/// Return the start position of a named capturing group.
155154
/// Returns -1 if the group exists but did not participate in the match.
156155
/// See https://docs.python.org/3/library/re.html#re.Match.start
157-
[<Emit("$0.start($1)")>]
158156
member _.start(group: string) : int = nativeOnly
159157

160158
/// Return the end position (exclusive) of the whole match in the original string.
161159
/// See https://docs.python.org/3/library/re.html#re.Match.end
162-
[<Emit("$0.end()")>]
163160
member _.``end``() : int = nativeOnly
164161

165162
/// Return the end position (exclusive) of a numbered capturing group.
@@ -171,7 +168,6 @@ type Match() =
171168
/// Return the end position (exclusive) of a named capturing group.
172169
/// Returns -1 if the group exists but did not participate in the match.
173170
/// See https://docs.python.org/3/library/re.html#re.Match.end
174-
[<Emit("$0.end($1)")>]
175171
member _.``end``(group: string) : int = nativeOnly
176172

177173
/// Return the (start, end) span of the whole match as a tuple.
@@ -187,7 +183,6 @@ type Match() =
187183
/// Return the (start, end) span of a named capturing group.
188184
/// Both values are -1 if the group did not participate in the match.
189185
/// See https://docs.python.org/3/library/re.html#re.Match.span
190-
[<Emit("$0.span($1)")>]
191186
member _.span(group: string) : int * int = nativeOnly
192187

193188
/// Return the string obtained by doing backslash substitution on the template string.
@@ -295,7 +290,6 @@ type IExports =
295290

296291
/// Compile a regular expression pattern with flags into a Pattern object.
297292
/// See https://docs.python.org/3/library/re.html#re.compile
298-
[<Emit("$0.compile($1, $2)")>]
299293
abstract compile: pattern: string * flags: int -> Pattern
300294

301295
// ========================================================================
@@ -310,7 +304,6 @@ type IExports =
310304
/// Try to match the pattern at the beginning of string, using the given flags.
311305
/// Returns None if the pattern does not match.
312306
/// See https://docs.python.org/3/library/re.html#re.match
313-
[<Emit("$0.match($1, $2, $3)")>]
314307
abstract ``match``: pattern: string * string: string * flags: int -> Match option
315308

316309
/// Scan through string looking for the first location where the pattern produces a match.
@@ -322,7 +315,6 @@ type IExports =
322315
/// using the given flags.
323316
/// Returns None if no position in the string matches.
324317
/// See https://docs.python.org/3/library/re.html#re.search
325-
[<Emit("$0.search($1, $2, $3)")>]
326318
abstract search: pattern: string * string: string * flags: int -> Match option
327319

328320
/// Try to match the pattern against all of the string.
@@ -333,7 +325,6 @@ type IExports =
333325
/// Try to match the pattern against all of the string, using the given flags.
334326
/// Returns None if the pattern does not match the entire string.
335327
/// See https://docs.python.org/3/library/re.html#re.fullmatch
336-
[<Emit("$0.fullmatch($1, $2, $3)")>]
337328
abstract fullmatch: pattern: string * string: string * flags: int -> Match option
338329

339330
// ========================================================================
@@ -347,7 +338,6 @@ type IExports =
347338

348339
/// Return all non-overlapping matches of pattern in string as a list of strings, with flags.
349340
/// See https://docs.python.org/3/library/re.html#re.findall
350-
[<Emit("$0.findall($1, $2, $3)")>]
351341
abstract findall: pattern: string * string: string * flags: int -> string[]
352342

353343
/// Return an iterator yielding Match objects for all non-overlapping matches of pattern in string.
@@ -357,7 +347,6 @@ type IExports =
357347
/// Return an iterator yielding Match objects for all non-overlapping matches of pattern in string,
358348
/// with flags.
359349
/// See https://docs.python.org/3/library/re.html#re.finditer
360-
[<Emit("$0.finditer($1, $2, $3)")>]
361350
abstract finditer: pattern: string * string: string * flags: int -> Match seq
362351

363352
// ========================================================================

0 commit comments

Comments
 (0)