Skip to content

UnboundLocalError in RegexPattern when initialized with pattern=None #98

@T90REAL

Description

@T90REAL

Description

RegexPattern crashes with UnboundLocalError when initialized with pattern=None and include=None, despite documentation stating that None is a valid pattern value for null operations.

Minimal Reproduction

from pathspec import RegexPattern

# This should create a null-operation pattern
pattern = RegexPattern(None, None)
Traceback (most recent call last):
  File "/data/src/test.py", line 4, in <module>
    pattern = RegexPattern(None, None)
              ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/py312/lib/python3.12/site-packages/pathspec/pattern.py", line 147, in __init__
    self.regex: PatternHint = regex
                              ^^^^^
UnboundLocalError: cannot access local variable 'regex' where it is not associated with a value

I think this is triggered when execution reaches self.regex = regex at the end, the uninitialized variable causes the error.

Environment

  • pathspec version: 0.12.1
  • Operating systems tested on: Linux

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions