| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 37d5fdd commit 3193adf
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,6 +1,6 @@ | |||
| 1 | 1 | # The MIT License | |
| 2 | 2 | # | |
| 3 | - # Copyright (c) 2015 Sebastian Ramacher | ||
| 3 | + # Copyright (c) 2015-2021 Sebastian Ramacher | ||
| 4 | 4 | # | |
| 5 | 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy | |
| 6 | 6 | # of this software and associated documentation files (the "Software"), to deal | |
@@ -20,8 +20,13 @@ | |||
| 20 | 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |
| 21 | 21 | # THE SOFTWARE. | |
| 22 | 22 | ||
| 23 | - import functools | ||
| 24 | 23 | import re | |
| 24 | + from typing import Optional, Iterator | ||
| 25 | + | ||
| 26 | + try: | ||
| 27 | + from functools import cached_property | ||
| 28 | + except ImportError: | ||
| 29 | + from backports.cached_property import cached_property # type: ignore | ||
| 25 | 30 | ||
| 26 | 31 | ||
| 27 | 32 | class LazyReCompile: | |
@@ -30,32 +35,22 @@ class LazyReCompile: | |||
| 30 | 35 | This class allows one to store regular expressions and compiles them on | |
| 31 | 36 | first use.""" | |
| 32 | 37 | ||
| 33 | - def __init__(self, regex, flags=0): | ||
| 38 | + def __init__(self, regex: str, flags: int = 0) -> None: | ||
| 34 | 39 | self.regex = regex | |
| 35 | 40 | self.flags = flags | |
| 36 | - self.compiled = None | ||
| 37 | - | ||
| 38 | - def compile_regex(method): | ||
| 39 | - @functools.wraps(method) | ||
| 40 | - def _impl(self, *args, **kwargs): | ||
| 41 | - if self.compiled is None: | ||
| 42 | - self.compiled = re.compile(self.regex, self.flags) | ||
| 43 | - return method(self, *args, **kwargs) | ||
| 44 | 41 | ||
| 45 | - return _impl | ||
| 42 | + @cached_property | ||
| 43 | + def compiled(self) -> re.Pattern: | ||
| 44 | + return re.compile(self.regex, self.flags) | ||
| 46 | 45 | ||
| 47 | - @compile_regex | ||
| 48 | - def finditer(self, *args, **kwargs): | ||
| 46 | + def finditer(self, *args, **kwargs) -> Iterator[re.Match]: | ||
| 49 | 47 | return self.compiled.finditer(*args, **kwargs) | |
| 50 | 48 | ||
| 51 | - @compile_regex | ||
| 52 | - def search(self, *args, **kwargs): | ||
| 49 | + def search(self, *args, **kwargs) -> Optional[re.Match]: | ||
| 53 | 50 | return self.compiled.search(*args, **kwargs) | |
| 54 | 51 | ||
| 55 | - @compile_regex | ||
| 56 | - def match(self, *args, **kwargs): | ||
| 52 | + def match(self, *args, **kwargs) -> Optional[re.Match]: | ||
| 57 | 53 | return self.compiled.match(*args, **kwargs) | |
| 58 | 54 | ||
| 59 | - @compile_regex | ||
| 60 | - def sub(self, *args, **kwargs): | ||
| 55 | + def sub(self, *args, **kwargs) -> str: | ||
| 61 | 56 | return self.compiled.sub(*args, **kwargs) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,7 +1,8 @@ | |||
| 1 | 1 | Pygments | |
| 2 | + backports.cached-property; python_version < "3.9" | ||
| 2 | 3 | curtsies >=0.3.5 | |
| 3 | 4 | cwcwidth | |
| 4 | 5 | greenlet | |
| 5 | 6 | pyxdg | |
| 6 | 7 | requests | |
| 7 | - setuptools | ||
| 8 | + setuptools | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -20,12 +20,13 @@ packages = | |||
| 20 | 20 | bpython.translations | |
| 21 | 21 | bpdb | |
| 22 | 22 | install_requires = | |
| 23 | - pygments | ||
| 24 | - requests | ||
| 23 | + backports.cached-property; python_version < "3.9" | ||
| 25 | 24 | curtsies >=0.3.5 | |
| 26 | - greenlet | ||
| 27 | 25 | cwcwidth | |
| 26 | + greenlet | ||
| 27 | + pygments | ||
| 28 | 28 | pyxdg | |
| 29 | + requests | ||
| 29 | 30 | ||
| 30 | 31 | [options.extras_require] | |
| 31 | 32 | clipboard = pyperclip | |
| Back | FazBrowse Home | New Git URL |
0 commit comments