Skip to content

Commit 7dd60c3

Browse files
authored
dot_parser: Define parser elements in a class (#464)
* core: Import dot_parser on demand * dot_parser: Move parser definition into class Instead of a global variable `graphparser` that's set by calling a function the first time it's referenced, set up the parser definition in a class `GraphParser`, so that it can be accessed as `GraphParser.parser`. This has the advantage that all of its _component_ parts (like the definition of `subgraph_stmt`, or `attr_list` can also be accessed as `GraphParser.subgraph_stmt` or `GraphParser.attr_list`, etc. (Much better for debugging/testing.) In addition, to improve dependency relationships: - Only import pydot.core into dot_parser, not `pydot` - Change all `pydot.Foo` references to `pydot.core.Foo` - Use concrete `pydot.core.Foo`s in type annotations (instead of strings) * Remove unused args from parse actions * parser: Remove unnecessary type-ignore from HTML.__init__ It annoyed mypy in strict mode. * dot_parser: Define 'graphparser' at module level Strictly for compatibility, in case anyone is using it directly. They probably shouldn't be, but this way we won't break their code. * Move low-end MyPy check to Python 3.9
1 parent 5681c3f commit 7dd60c3

File tree

3 files changed

+134
-147
lines changed

3 files changed

+134
-147
lines changed

setup.cfg

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,5 +61,5 @@ python =
6161
3.12 = py312
6262
3.11 = py311
6363
3.10 = py310
64-
3.9 = py39
65-
3.8 = mypy-check, py38
64+
3.9 = mypy-check, py39
65+
3.8 = py38

src/pydot/core.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
from typing import Any, List, Optional, Sequence, Set, Tuple, Type, Union, cast
1616

1717
import pydot
18-
import pydot.dot_parser
1918
from pydot._vendor import tempfile
2019
from pydot.classes import AttributeDict, FrozenDict
2120

@@ -401,6 +400,8 @@ def graph_from_dot_data(s: str) -> Optional[List["Dot"]]:
401400
@return: Graphs that result from parsing.
402401
@rtype: `list` of `pydot.Dot`
403402
"""
403+
import pydot.dot_parser
404+
404405
return pydot.dot_parser.parse_dot_data(s)
405406

406407

0 commit comments

Comments
 (0)