Code

Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#15928 closed New feature (wontfix)

RegexField and regexp flags

Reported by: Sergey N. Belinsky <sergeybe@…> Owned by: nobody
Component: Forms Version: 1.3
Severity: Normal Keywords: RegexField unicode re.compile
Cc: Triage Stage: Design decision needed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX:

Description

The syntax of re.compile function is:

regexp = re.compile(pattern[, flags])

but this function in RegexField used without flags. I suggest to use the next syntax for RegexField:

login = RegexField(r'\w+', flags=re.UNICODE|re.IGNORE)

I guess it will be useful. Thank you!

Attachments (0)

Change History (3)

comment:1 Changed 3 years ago by anonymous

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Design decision needed

Based on the docs, RegexField.regex is a "regular expression specified either as a string or a compiled regular expression object.".

Your example could be written like this:

login = RegexField(re.compile(r'^\w+', flags=re.UNICODE|re.IGNORE))

And also like this—it's slightly shorter but less readable:

login = RegexField(r'(?ui)^\w+')

IMO this is sufficient and it's not necessary to add a flags parameter to RegexField, but others may feel differently. I'll mark the ticket as DDN.

comment:2 Changed 3 years ago by anonymous

  • Resolution set to wontfix
  • Status changed from new to closed

Yes, you are right! I agree with you. Your examples are better. The extra parameter isn't need. Thank you!
I will close the ticket.

comment:3 Changed 3 years ago by jacob

  • milestone 1.4 deleted

Milestone 1.4 deleted

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.