Skip to content

Commit

Permalink
fixup! Use python 3.7's getattr for the lazy-init global parser
Browse files Browse the repository at this point in the history
  • Loading branch information
masklinn committed Oct 25, 2023
1 parent dbf49ca commit d21c3c4
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/ua_parser/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@


parser: Parser


def __getattr__(name):
global parser
if name == "parser":
Expand All @@ -49,6 +51,7 @@ def parse(ua: str) -> ParseResult:
you're not going to use *all* of them.
"""
from . import parser

return parser.parse(ua)


Expand All @@ -57,6 +60,7 @@ def parse_user_agent(ua: str) -> Optional[UserAgent]:
:func:`global parser <get_parser>`.
"""
from . import parser

return parser.parse_user_agent(ua)


Expand All @@ -65,6 +69,7 @@ def parse_os(ua: str) -> Optional[OS]:
<get_parser>`.
"""
from . import parser

return parser.parse_os(ua)


Expand All @@ -73,4 +78,5 @@ def parse_device(ua: str) -> Optional[Device]:
parser <get_parser>`.
"""
from . import parser

return parser.parse_device(ua)

0 comments on commit d21c3c4

Please sign in to comment.